Merging arrays is a fairly common occurrence. I remember when I worked a lot with PHP I would use
array_merge() all the time. I found myself merging arrays often when handling form submission.
concat may mess up a reference. If you want to merge a second array into an existing first array, you can use this trick:
var array1 = [1, 2, 3]; var array2 = [4, 5, 6]; Array.prototype.push.apply(array1, array2); console.log(array1); // is: [1, 2, 3, 4, 5, 6]
push in this case, allows you to merge the second array into the first. The alternative is iterating through the second array and using
push on the first array. This shortcut is niiiiiiiiiice!