我在for循环中动态创建数组。这是完美的作品,但我不知道如何从另一个功能访问阵列访问动态创建的数组
$(document).ready(function() {
var title = "This is a title";
var paragraph = "Praesent id metus massa, ut blandit odio.";
w = window;
for (i=0; i<10; i++){
w["arr_"+i] = [];
w["arr_"+i].push(title + i);
w["arr_"+i].push(paragraph);
console.log(w["arr_"+i]);
}
});
function showArray(){
//I want to use the array data here
// this returns "arr3 is not defined "
console.log(arr3);
}
showArray();
um您添加到窗口对象的数组属性是arr_,所以肯定console.log(arr_3)会更合适? – OJay