One of my challenges involves working with a JSON object structured like this:
var Obj = {
'id1': 'abc',
'id2': 'pqr',
'id3': 'xyz'
}
In my code, I have an asynchronous method being called within a loop, as shown below:
var otherObj = {};
for (i in Obj) {
var someData = Obj[i];
File.upload(someData).then(function(response) {
otherObj[i] = response.data.url;
});
}
However, the resulting otherObj
looks like this:
otherObj = {
'id3':'url1',
'id3':'url2',
'id3':'url3',
}
This issue prompts me to inquire about the best approach for linking each key from the Obj
object with its respective response from File.upload()
.