How can I access globally declared array inside my each loop? When I try, it returns undefined. I tried adding window.
prefix
如何在每个循环中访问全局声明的数组?当我尝试时,它返回的是未定义的。我试着添加窗口。前缀
var array = [];
$( document ).scroll(function() {
console.log(array);
//returns array contents
$('div').each(function(){
console.log(array);
//returns undefined
});
});
1 个解决方案
#1
0
var array = [1,54,2];
console.log(array);
$(array).each(function(index,value){
console.log(value);
});
#1
0
var array = [1,54,2];
console.log(array);
$(array).each(function(index,value){
console.log(value);
});