I have difficulties with iterating through array of objects which contains image. As my code below shows the array in console looks kind of empty but when I open it in console, I see all this objects also with iteration numbers. I can't google and get to the point how to transform it into proper working array to make for in loop and iterate through it in Vue.js. I attach you the code where comments says more than my description.
const frameImage = [
{
url: 'http://www.realmadryt.pl/fotki/_up/newsy/lukamodric_165.png'
},
{
url: 'http://www.realmadryt.pl/fotki/_up/newsy/florentinoperez_11.jpg'
},
{
url: 'http://www.realmadryt.pl/fotki/_up/newsy/ramosbarkinsta1.jpg'
},
{
url: 'http://www.realmadryt.pl/fotki/_up/newsy/lukamodric_165.png'
},
{
url: 'http://www.realmadryt.pl/fotki/_up/newsy/florentinoperez_11.jpg'
},
{
url: 'http://www.realmadryt.pl/fotki/_up/newsy/ramosbarkinsta1.jpg'
},
];
let createdImages = [];
frameImage.forEach(item => {
const image = new Image();
image.src = item.url;
image.onload = () => {
// set image only when it is loaded
createdImages.push({
image,
width: image.width,
height: image.height,
x: 0,
y: 0,
draggable: true
});
};
});
console.log(createdImages)
// nothing happens
createdImages.forEach(item => {
console.log(item)
});
//also nothing happens
for(img in createdImages) {
console.log(img);
}
//length is actually 0?
console.log(createdImages.length)
Also jsFiddle: LINK