I have a problem with creating list with objects in JavaScript: the object is going to contain an Integer value and an array.
The structure will look like this (this code works):
var list = [ {
id : 1234,
dependencyList : [ {
id : 2142
}, {
id : 5313
} ]
}, {
id : 4312,
dependencyList : [ {
id : 2142
}, {
id : 5313
} ]
} ];
The problem is that I want to create this list dynamically, in other words something like this:
var list = [];
var object;
object.id=1234;
object.dependencyList = [];
object.dependencyList.push(2222);
list.push(object);
This code does not work when I try to alert(list[0].length) and it returns 0 and after using JSON.stringify(list) it only returns [[]].
Anyone know a solution for this?
list[0] == { id : 1234, dependencyList : [ { id : 2142 }, { id : 5313 } ] }var object = {};???list = { 1234 : [ 2142, 5313], 4312 : [2142, 5313] };