When I am trying to add values to a JSON object manually, it works fine:
Code:
for (var k = 0; k < result.length; k++) {
result[k]["sender"] = k;
}
https://i.sstatic.net/jnbpw.png
However, when I fetch values from an API and attempt to store them in result[k]["sender"]
, the values are not being saved in the JSON object, and instead, they are being printed on the console:
for (var k = 0; k < result.length; k++) {
var url = "//api";
$.ajax({
url: "https://reverse.geocoder.api.here.com/6.2/reversegeocode.json?prox="+result[k]['lat'].toString()+","+result[k]['lon']+"&mode=retrieveAddresses&app_id=***&app_code=***",
context: document.body,
success: function (data) {
console.log(k, typeof data['Response']['View'][0]['Result'][0]['Location']['Address']['Label']);
result[k]["sender"] = data['Response']['View'][0]['Result'][0]['Location']['Address']['Label'];
}
});
}
Error: https://i.sstatic.net/cpoAt.png
Could someone provide guidance on what might be causing this issue?