198
rated 0 times
[
200]
[
2]
/ answers: 1 / hits: 39590
/ 8 Years ago, fri, february 26, 2016, 12:00:00
Java Collections have a method to add all elements of another collection: addAll(Collection other)
.
What is the equivalent to do in place appending of javascript arrays?
We cannot use Array.concat
, because it creates a new array and leaves the original array untouched.
So, given two arrays, how b
to a
, how to append all elements of b
to a
in place (therefore c
also changes!):
var a = [1, 2, 3];
var b = ['foo', 'bar'];
var c = a;
// a.addAll(b);
// so that `c` equals to [1, 2, 3, 'foo', 'bar']
More From » arrays