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);