Array class
The ToString () method and the ValueOf () method return a special string. The string is formed by calling the ToString () method on each item and then connecting them together with commas. For example, call the ToString () method or the ValueOf () method on an array that has the item "red", "green", and "blue", and return the string "Red,green,blue".
The only purpose of the join () method is to concatenate string values. The join () method has only one parameter, which is the string used between the array items.
The split () method converts a string into an array, and the split () method has only one parameter, which is a string that is treated as a delimiter between the items in the list. If an empty string is declared as a delimiter, then each item in the array returned by the split () method is a character of the string.
The Concat () method handles an array in almost the same way that it handles a string. The parameter is appended to the end of the array, and the function value returned is the new array object (including the items in the original array and the new item).
The slice () method accepts one or two parameters, that is, the starting and ending positions of the items to be extracted. If there is only one argument, the method returns all items starting at that position to the end of the array, and if there are two parameters, the method returns all items between the first and second positions, excluding the item at the second position .
The Unshift () method, which places an item in the first position of the array, and then moves the remaining item down one position.
The reverse () method reverses the order of the array items.
The sort () method sorts the array items according to their values in ascending order. ( Note: just sort the string code, the sorting of the number array requires another solution)
The Splice () method is the most complex method of inserting data items into the middle of an array.
1. Delete--just declare two parameters, you can delete any number of items from the array, the two parameters are the position of the first item to be deleted and the number of items to be deleted. For example, Arr.splice (0,2) will delete the first two entries in the array arr.
2. Replace without deleting--declare three parameters to insert the data item into the specified position, these three parameters are the starting position, 0 (the number of array items to delete) and the item to be inserted. In addition, you can specify additional items to insert with the fourth, fifth, or more parameters. For example, Arr.splice (2,0, "Red", "green") will insert "red" and "green" at position 2.
3. Replace and delete--declare three parameters to insert the data item into the specified position, the three parameters are the starting position, the number of array items to delete, and the item to insert. In addition, you can specify more items to insert. The number of items to insert does not have to be equal to the number of items deleted. For example, Arr.splice (2,1, "Red", "green") will delete the entry at position 2 in arr, and then insert "red" and "green" at position 2.
JavaScript Array class