How can I update this javascript array using JS Remoting?
var data = [];
Visualforce.remoting.Manager.invokeAction('{$RemoteAction.myController.myMethod}',
function(result, event) {
if (event.status) {
for (var i=0; i<result.length; i++) {
data.push({myKey: result[i].fieldName});
}
console.log(data);
} else {
alret(event.message)
}
},
{escape: true}
);
console.log(Array.isArray(data));
console.log(data);
console.log(data.length);
console.log(data[1].myKey);
Apex controller is supposed to return 4 records, so as expected, from inside invokeAction, javascript console print out this.
But after it passes through invokeAction, I got these from the last four lines of codes above.
Any idea? Thanks.