This article illustrates the difference between JS array merge push and concat. Share to everyone for your reference, specific as follows:
Note that the concat spelling, the two functions are very similar, but there are two points difference.
First look at the code:
var arr = [];
Arr.push (1);
Arr.push ([2, 3]);
Arr.push (4, 5);
arr = Arr.concat (6);
arr = Arr.concat ([7, 8]);
arr = Arr.concat (9);
Arr.each (function (index, value) {
alert (value);
});
Alert Result:
Difference:
When a push encounters an array parameter, it takes the entire array parameter as an element, while concat the array parameter and adds an element to it.
Push changes the current array directly; Concat does not change the current array.
Summarize:
If you want to append the array with concat, but like the Java Replace, remember Arr1=arr1.concat (ARR2)
I hope this article will help you with JavaScript programming.