我现在有点问题。我尝试使用全局数组并在一个函数中存储信息,并尝试在另一个函数中使用其中的信息,但是当我尝试访问该信息时,它显示为空,即使我在访问信息之前调用该函数。这是一个示例代码:
var myArray = [];
functionThatLoops(parameter_Array, parameter2){
for (item in parameter_Array){
$.get(URL,
{
method: "endPointMethod",
id: item["ID"]
}, function(data){
myArray.push(data)
});
}
}
mainFunction(){
c = 1;
for (array in AnotherMultiDimensionalArray){
functionThatLoops(array,c);
}
console.log(myArray) //Displays Array with correct number of elements and correct info
console.log(myArray.length) //Displays 0 and after this array appears to be empty
for (item in myArray){ //Nothing prints out in this loop, as array appears empty
console.log(item)
}
}
可能是什么问题?看起来填充数组的代码最后执行...