In JavaScript, we generally only use push to insert new elements into the end of the array, but in fact there is another method in JavaScript, like push, that inserts new elements into the end of the array, but there is a certain difference between them. When we look at the following code, it is obvious that:
1. By using the push operation array:
2. Manipulate an array by using the concat:
from the above two operations it is obvious that the difference between push and concat
When push encounters an array parameter, the entire array parameter is inserted as an object, while the concat is an array parameter, and an element is added to it.
Push changes the current array directly; Concat does not change the current array.
The following code proves the difference above, the code is as follows:
<script>var colors=["Red", "Blue", "green"]; var a={name: "Zhang San"}; var count=// output: 4// output: Red,blue,green,[object Object]colors= Colors.concat (a); Alert (colors[3]); // output: Red,blue,green,[object Object],[object Object] It is obvious that concat splits a collection into a name object and a "Zhang San" object, while push is a as an object </script>
The difference between the concat () and push () methods of a JavaScript reference type array