最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript nested array - Stack Overflow

programmeradmin3浏览0评论

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
Add a ment  | 

1 Answer 1

Reset to default 10

Because 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);
发布评论

评论列表(0)

  1. 暂无评论