javascript - 访问动态创建的数组

标签 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();

最佳答案

您的代码中有下划线。

console.log(arr_3);

关于javascript - 访问动态创建的数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23234440/

相关文章:

javascript - ESLint/Prettier -- 强制执行 max-len/printWidth,但不需要它?

javascript - 在键入值或选择更改时连接值

javascript - 如何返回javascript数组中的所有对象

python - numpy.concatenation 的问题

无法在 C 中声明指向结构内部结构的指针数组

javascript - 为什么 parseInt(str) 不返回整数?

javascript - 如何统计 Bing map 中的大量图钉?

javascript - 跨多页面表单使用 ember-cp-validations

将文件复制到数组中但不会打印?

java - Java 中的收缩数组保持数字分布