This article mainly introduces the differences between JS array merge push and concat, and analyzes the differences between the use of push and concat for array merge operations in JavaScript in the form of examples, for more information about the differences between JS array merge push and concat, see the examples in this article. We will share this with you for your reference. The details are as follows:
Note the concat spelling. the two functions are similar, but there are two differences.
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, 10); arr. each (function (index, value) {alert (value );});
Alert result:
12,345678910
Differences:
When an array parameter is encountered in push, the entire array parameter is used as an element, while concat is used to split the array parameter and add one element to the element.
Push directly changes the current array; concat does not change the current array.
Summary:
If you want to append an array with concat, but it is the same as java's replace, remember to use arr1 = arr1.concat (arr2)
I hope this article will help you design JavaScript programs.