I 'm currently having a hard time figuring out why an object is once defined and on the next line it is not.
In my code, I'm declaring a promise with a for loop inside, that loops through a couple of file inputs and checks the files(images) dimension. Once all inputs are processed the promise is resolved and the then method fires.
for(var i = 0; i < $('.apk-wrapper .mandatoryImg').length; i++){
if ($('.apk-wrapper .mandatoryImg')[i].value){
var id = $($('.apk-wrapper .mandatoryImg')[i]).attr('id');
var imageProcessing = new Promise(function(resolve,reject){
if(id == 'game_icon'){
imageProcessor($('.apk-wrapper .mandatoryImg')[i],512,512)
}
else if(id == 'ingame1'){
imageProcessor($('.apk-wrapper .mandatoryImg')[i],720,1280)
}
...
else{
error = true;
reject()
}
if(i == $('.apk-wrapper .mandatoryImg').length - 1){
resolve(images)
}
}
}).then(function(images){
console.log(images)
// console.log(images.length)
})
If I now log the array of processed images I get the correct Object with indexes.
Array[0]
0:File
1:File
2:File
3:File
4:File
5:File
length:6
When I try to get the length of that object, I tried multiple methods(.length, while hasOwnProperty, for keys in x), I always get back 0.