In array operations, push () is common, concat () is very rare, but the use of the two is very similar, it can be understood that push () is a simplified version of Concat (), first look at the following example:
/*push () method * *
var array=[1,2,3,4,5];
Console.log (array); [1, 2, 3, 4, 5]
Array.push (6); A parameter
console.log (array); [1, 2, 3, 4, 5, 6]
Array.push (6,7); Two parameters
Console.log (array); [1, 2, 3, 4, 5, 6, 7]
array.push ([6,7]); Parameters are array
console.log (array); [1, 2, 3, 4, 5, 6, Array (2)]
/*concat () method * *
var array=[1,2,3,4,5];
Console.log (array); [1, 2, 3, 4, 5]
var array2=array.concat (6); A parameter
console.log (array); [1, 2, 3, 4, 5]
console.log (array2); [1, 2, 3, 4, 5, 6]
var array2=array.concat (6,7); Two parameters
Console.log (array); [1, 2, 3, 4, 5]
console.log (array2); [1, 2, 3, 4, 5, 6,7]
var array2=array.concat ([6,7]); Parameters are array
console.log (array); [1, 2, 3, 4, 5]
console.log (array2); [1, 2, 3, 4, 5, 6, 7]
A few differences can be seen through the code:
The 1,push () is modified on the basis of the original array, and the value of the original array is changed after the push () method is executed; Concat () first copies the original array to a new array and then operates on the new array, so it does not change the value of the original array.
2, if the parameter is not an array, regardless of the number of parameters, push () and concat () add parameters directly to the array, and if the argument is an array, push () adds the array directly to the original array, and concat () takes the value out of the array and adds it to the original array.