我要声明并填充我的JS数组,如下所示。但是回显该变量将其显示为空。为什么会这样?
let obj = new Array();
$.ajax({
url : 'backend/test.php',
type : 'GET', // type of the HTTP request
success : function(data){
obj = data;
//console.log(obj); --- at this point shows the JSON object populated.
}
});
console.log(obj);// -- at this point the object is empty!