Here we have a JSON object structured like this:
var items = [{
title: 'example 1',
image: 'http://www.lorempixel.com/700/600/'
}, {
title: 'example 2',
image: 'http://www.lorempixel.com/900/1200/'
}, {
title: 'example 3',
image: 'http://www.lorempixel.com/400/300/'
}, {
title: 'example 4',
image: 'http://www.lorempixel.com/600/600/'
}, {
title: 'example 5',
image: 'http://www.lorempixel.com/400/310/'
}, {
title: 'example 6',
image: 'http://www.lorempixel.com/410/300/'
}, {
title: 'example 7',
image: 'http://www.lorempixel.com/500/300/'
}, {
title: 'example 8',
image: 'http://www.lorempixel.com/300/300/'
}, {
title: 'example 9',
image: 'http://www.lorempixel.com/450/320/'
}, {
title: 'example 10',
image: 'http://www.lorempixel.com/500/400/'
}];
The goal is to create an array in the following format:
[['example 1', 'http://www.lorempixel.com/700/600/'], ['example 2', 'http://www.lorempixel.com/900/1200/'], ....]
Initially, an attempt was made in the code snippet below:
const rows = [];
for (let i = 0; i < items.length; i++) {
const element = items[i];
rows[i] = element.title;
for (let j = i; j < items.image; j++) {
const el = response[j];
rows[j] = el.image;
}
}
However, this resulted in only images being stored in the array due to overriding values during the second loop. What would be the correct approach to retrieve both values as intended?