Methods of arrays
//1. Concat () (concat in English: merging arrays; merging multiple strings;)
var colors = ["Red", "green", "Blue"];
var Color2 = Colors.concat ("Yellow", ["Black", "Brown"]);
console. log (colors);//["Red", "green", "Blue"
console. log (Color2);//["Red", "green", "blue", "yellow", "black", "Brown"]
//Summary: concat merge array, original array unchanged, new array is passed in the original array and concat array of arguments
//2. Slice () Slice 's English interpretation: cut into pieces;
var colors = ["Red", "green","Blue", "yellow", "Purole");
var Color2 = Colors.slice (1);
var Color3 = Colors.slice (1, 3);
console. log (colors);//"Red", "green", "blue", "yellow", "purole"]
console. log (Color2);//["Green", "blue", "yellow", "purole"]
console. log (Color3);//["Green", "blue"]
//Summary: Slice (x, y) cut an array, the original array is unchanged, X begins to cut the array subscript, the position where Y ends but excludes the position is the value of the previous position of Y subscript, the value of x and Y can be negative, the last element of the array is subscript 1, if x, Y is negative, Then Array.slice (x, y) is the same as the result of Array.Length (x + array.length, y + aray.length). If there is only one value, start the cut from that value until the end of the array
//3. Splice () (the most powerful array method) (Splice English interpretation : stranding, twisting (two-segment rope), adhesive bonding, bonding (film, tape, etc.);
//delete
var colors = ["Red", "green", "Blue"];
var Remove = Colors.splice (0, 1);
console. log (colors);//["Green", "blue"]
console.log (remove); ["Red"]
//Insert
Remove = Colors.splice (1, 0, "Yellow", "Orange");
console. log (colors);//["green", "yellow", "orange", "Blue"]
console.log (remove); //[]
//Replace
Remove = Colors.splice (1, 1, "Red", "purple");
console. log (colors);//["Green", "red", "purple", "orange", "Blue"
console.log (remove); ["Yellow"]
//Summary: Splice (x, y) two parameters of the time for deletion, X is the position to start deletion, Y is the number of deletions , The return value is the deleted array element
//Splice (x, 0, "Red", "green"), X is the position to begin deletion, 0 is the number of deletions, the third parameter is inserted after the X position of the array, and the return value is a Empty array, because there's nothing.
// splice (x, Y, "red", "green"), X is the position to begin deletion, Y is the number of deletions, first deleted and then added from the X position is replaced , The return value is /c1> the deleted array element
JS array of concat, slice, splice method