0
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/'
}];

Instead of hard coding this, I would like to create this exact same array dynamically - here is my code.

for(var key in pics) {
    var items[];
    items.push(pics[key].source);
}

I dont think this works because it just pushes the images into a standard array like this:

items = [1.jpg, 2.jpg....];

How can I accomplish this,cheers.

0

1 Answer 1

1

I don't know where you get the img url and i assume pics.source is the title:

var items = [];
for(var key in pics) {
    items.push({title: pics[key].source, image: <img url>});
}
Sign up to request clarification or add additional context in comments.

1 Comment

Im fetching the img url remotely

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.