0

I want to push an array in the other array.I know concat() but what i want is not this.
Two dimensional array
perhaps:

    var a = [],b = [],c = [];
a.push(1);
b.push(a);
console.log(b);      //[[1]]
a.push(2);
console.log(b)       //[[1,2]]
a.push(3);           
console.log(b)       //[[1,2,3]]

b will be changed if a is changed,what i want is

 var a = [],b = [],c = [];
a.push(1);
b.push(a);
console.log(b)       //[[1]]
a.push(2);
console.log(b)       //[[1]]
a.push(3);           
console.log(b)       //[[1]]
YXC.Coder
  • 41
  • 6

2 Answers2

1

You could point to a two dimension array like b[1][0].

you could use the following code to push an array values into another array

b.push(JSON.parse(JSON.stringify(a));
fingerpich
  • 8,500
  • 2
  • 22
  • 32
0

To append array a onto array b, you can simply concatenate your arrays a and b together, as follows,

var a = a.concat(b);

or

var a = [].concat(a,b);

Both of these examples will return a combined array with all elements from both a and b.

Trent
  • 4,208
  • 5
  • 24
  • 46