Reputation: 259
I am pushing a value into a table. But when i try to print it out in my console.log
I get undefined, but I know I'm pushing a value that is not undefined.
var attachmentIds = [];
for(var i = 0; i < files.length; i++){
uploadFileToServer(files[i]).then(function(data){
console.log(data[2]);
if(data[0]){
completed();
}else if(!data[0]){
completed();
uploadFileStatus.push({file: data[1].name, uploaded: data[0], message: data[2]});
}
attachmentIds.push(data[2]);
console.log(attachmentIds[i]);
});
};
[10:53:51.492] ""533d219fff0006d40ced67ab""
[10:53:51.493] undefined
Here is my 2 console logs
Upvotes: 0
Views: 34
Reputation: 2086
You are manipulating attachmentIds inside then(). This is handled asynchron. So you dont know which value i has when logging attachmentIds[i]. Try logging the whole array attachmendIds and you should see your data.
Upvotes: 1