I've a JSON object like this
var Obj = {
'id1': 'abc',
'id2': 'pqr',
'id3': 'xyz'
}
and I'm calling async method while iterating, like this
var otherObj = {};
for (i in Obj) {
var someData = Obj[i];
File.upload(someData).then(function(response) {
otherObj[i] = response.data.url;
});
}
But in this I'm getting otherObj as
otherObj = {
'id3':'url1',
'id3':'url2',
'id3':'url3',
}
So my question is what is the best way to correctly associate each key present in Obj
object with the response of File.upload()
.