Adding data to a Javascript array of arrays -
i'm trying add data array, , getting weird result.
var arr = []; var obj1 = { data: ["a","b"]}; var obj2 = { data: ["c","d"]}; arr.push(obj1); arr[0].data.push(obj2.data); console.log(arr[0].data); // 1) want: [ ["a", "b"], ["c", "d"] ] // 2) get: ["a", "b", ["c", "d"] ]
any idea how can set data formatted like: [["a","b"],["c","d"]]? here's fiddle it: http://jsfiddle.net/oakley808/ucq65/
try this:
var arr = []; var obj1 = { data: ["a","b"]}; var obj2 = { data: ["c","d"]}; arr.push(obj1.data); arr.push(obj2.data); console.log(arr);
Comments
Post a Comment