How to Extend an Existing JavaScript Array with Another Array Without Creating a New Array
There are multiple widely used methods that will extend an existing JavaScript Array with another one without creating a new Array. This tutorial will help you resolve this issue right away.
push()
The push() method is generally used to push an array to the end of an existing one. In ES5 specification, this is often done as follows:
If your browser supports ES6, you can use the spread operator:
The push() method can take more than one parameters, so you can use the apply() method for passing the array of values to be pushed as a list of function parameters:
concat()
You can use the concat() method to extend an existing array in JavaScript:
Beware of using the concat() method which returns a new array instead of changing the existing array containing the values of the merged arrays. However, it is also technically right for this particular situation.