I have an Object that contains an associative array
The value stored in the array is an Object
Within the each function, I want to access one of the values in the value object (responseText)
My code is as follows
var apiNameArray = getDataSourceApiNames();
var apiResults = {};
var deferred;
for (let i = 0; i < apiNameArray.length; i++) {
var apiName = apiNameArray[i];
console.log("apiName = " + apiName);
deferred = $.ajax({
type: "GET",
url: api_URL + "memberdetails/" + memberNumber,
contentType: "application/json; charset=utf-8",
dataType: "json"
}
);
apiResults[apiName] = deferred;
}
$.when.apply($, apiResults).then(function () {
console.log(apiResults);
$.each(apiResults, function (key, value) {
console.log(key);
console.log(value);
console.log(value.responseText);
});
});
For some reason, value.responseText is returning undefined. How am I suppose to be accessing this value/property? I have tried value["responseText"], apiResults[key].responseText all with no success


JSON.parse()method.console.log(apiResults);then you can simply access the responseText likeapiResults[0]['responseText']. You can replace the0with a loop index.