我在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