admin管理员组文章数量:1394990
Hi I want to use nested arrays in my javascript function but it doesn't work. Here is my function:
var arr = [];
function test(id, value){
arr.push(new Array("id" = id, "value" = value));
}
so as you find out I want to create something like this:
arr[0][id = "example0", value = "value0"];
arr[1][id = "example1", value = "value1"];
arr[2][id = "example2", value = "value2"];
...
Hi I want to use nested arrays in my javascript function but it doesn't work. Here is my function:
var arr = [];
function test(id, value){
arr.push(new Array("id" = id, "value" = value));
}
so as you find out I want to create something like this:
arr[0][id = "example0", value = "value0"];
arr[1][id = "example1", value = "value1"];
arr[2][id = "example2", value = "value2"];
...
Share
Improve this question
asked Sep 1, 2012 at 12:16
IrakliIrakli
1,1436 gold badges30 silver badges56 bronze badges
1 Answer
Reset to default 10Because new Array("id" = id, "value" = value)
is not an array.
You want an array holding an object.
arr.push({"id":id, "value":value});
Read values
console.log(arr[0].id);
本文标签: javascript nested arrayStack Overflow
版权声明:本文标题:javascript nested array - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744109734a2591234.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论