访问动态创建的数组

时间:2014-04-23 03:53:09

标签: javascript arrays

我在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();

1 个答案:

答案 0 :(得分:3)

您的代码中有下划线。

console.log(arr_3);