When you are working with multiple arrays, sometimes you'll want to merge them in a single array.
You could iterate through one of them and add each value to the end of the other array, but thats inefficient and modifies one of the arrays.
In this post, we'll look at two ways to merge arrays without modifying either one in JavaScript.
Using concat
One way to merge arrays is to use the concat function.
This function is built-in for arrays and will return a new array containing the values of the original array and the secondary array that you pass in as the parameter.