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

enter image description here


Comments

Popular posts from this blog

jquery - How can I dynamically add a browser tab? -

keyboard - C++ GetAsyncKeyState alternative -

android - java.net.UnknownHostException(Unable to resolve host “URL”: No address associated with hostname) -