Have a Javascript array that I'm creating and pushing objects to :
checkedAPBoxes.each( function() {
let APTempObj = {};
let apSequence = $(this).data('sequence');
let arDropdownSequenceValue = $('#billingRelaseSelectTiedAR' + $(this).data('sequence')).val();
APTempObj.apSequenceToRelease = apSequence;
APTempObj.relatedARSequence = arDropdownSequenceValue;
APArray.push(APTempObj);
//check if current invoice is comcheck
const url = '/cfc/shipments/ap/ShipmentAPAPI.cfc';
const data = {
method: 'isOriginalComcheckInvoice',
shipmentID: shipmentID,
sequence: apSequence,
returnformat: 'JSON'
};
Edge.Utility.Ajax.get(url, data)
.then(function(result) {
if (result == true){
//add related comcheck invoices to batch
const comcheckURL = '/cfc/shipments/ap/ShipmentAPAPI.cfc';
const comcheckData = {
method: 'getRelatedComcheckInvoices',
shipmentID: shipmentID,
sequence: apSequence,
returnformat: 'json'
};
Edge.Utility.Ajax.get(comcheckURL, comcheckData)
.then(function(resultAPs) {
for (var i = 0; i < resultAPs.length; i++) {
let relatedAPTempObj = {};
relatedAPTempObj.apSequenceToRelease = parseInt(resultAPs[i]);
relatedAPTempObj.relatedARSequence = arDropdownSequenceValue;
APArray.push(relatedAPTempObj);
}
}).catch(function(xhr) {
console.error(xhr);
$uiButton.eui('button', 'complete');
$uiButton.show();
});
}
}).catch(function(xhr) {
console.error(xhr);
$uiButton.eui('button', 'complete');
$uiButton.show();
});
});
But logging the array shows me a length of 5 yet only 3 objects in there:

Looping over the array based on length only prints the first three elements thought, even though length shows 5.
for (var i = 0; i < APArray.length; i++) {
console.log('typeof: ' + typeof(APArray[i]));
console.log(APArray[i]);
}
APArraybefore the network response was received.Array[3]in the first line indicates that at the time the array is logged it only has 3 elements. By the time you expand the log it has 5. Hover over theinext toArray[3].