1, concat () creates a new array based on all the items in the current array.
Specifically, this method creates a copy of the current array, adds the received parameters to the end of the copy, and returns the newly constructed array. In the case where no arguments are passed to the concat () method, it simply copies the current array and returns a copy, and if passed to the Concat () method is one or more arrays, the method adds each item in those arrays to the result array. If the pass is not an array, these values are simply added to the end of the result array.
var colors = ["Red", "green", "Blue"]; var colors2 = colors. concat ("Yellow", ["Black", "Brown"]); alert (colors); // red,green,bluealert (colors2); // Red,green,blue,yellow,black,brown
2, Slice () creates a new array based on one or more items in the current array.
The slice () method can accept one or two parameters, that is, to return the starting and ending positions of an item.
In the case of only one argument , the slice () method returns all items starting at the specified position of the parameter to the end of the current array.
If there are two parameters , the method returns the entry between the start and end positions, but not the ending position .
Note that the slice () method does not affect the original array. Take a look at the following example:
var colors = ["Red", "green", "blue", "yellow", "brown"]; var colors2 = colors. Slice (1); var colors3 = colors. Slice (1, 3); alert (colors2); // green, blue, yellow, brownalert (COLORS3); // Green, Blue
If the slice () method has a negative number in its argument, the array length is used to determine the corresponding position. For example, calling Slice (-2,-1) on an array containing 5 items is the same as calling Slice (3, 4). If the end position is less than the start position, an empty array is returned.
Operation of Arrays (array)