Given is an json object like this:
var items = [{
title: 'sample 1',
image: 'http://www.lorempixel.com/700/600/'
}, {
title: 'sample 2',
image: 'http://www.lorempixel.com/900/1200/'
}, {
title: 'sample 3',
image: 'http://www.lorempixel.com/400/300/'
}, {
title: 'sample 4',
image: 'http://www.lorempixel.com/600/600/'
}, {
title: 'sample 5',
image: 'http://www.lorempixel.com/400/310/'
}, {
title: 'sample 6',
image: 'http://www.lorempixel.com/410/300/'
}, {
title: 'sample 7',
image: 'http://www.lorempixel.com/500/300/'
}, {
title: 'sample 8',
image: 'http://www.lorempixel.com/300/300/'
}, {
title: 'sample 9',
image: 'http://www.lorempixel.com/450/320/'
}, {
title: 'sample 10',
image: 'http://www.lorempixel.com/500/400/'
}];
I Want to get an array like this.
[['sample 1', 'http://www.lorempixel.com/700/600/'], ['sample 2', 'http://www.lorempixel.com/900/1200/'], ....]
I tried something like this:
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;
}
}
I get an array containing only all images, i think because i override other values in the second loop. What should be the right way to get both values like described ?