Often see these three functions, I will be very Meng, must go to the Internet search; today, happen to see them again, so presumably it is time for them to make a note
1.slice (Array)
Usage: Array.slice (start,end)
Explanation: This method is partially truncated to an array and returns a copy of it; parameter start is the zero-based array index of the intercept, and the end parameter equals the position value of the last character you want to take, plus 1 (optional)
If parameter two is not passed in, it will be truncated from the index of parameter one to the end of the array
var a=[1,2,3,4,5,6];
var b=a.slice (0,3); [1,2,3]
var c=a.slice (3); [4,5,6]
///If either of the two parameters is a negative number, the array.length adds to them, trying to make them non-negative, for example:
//When only one argument is passed, length is added to the parameter, and then the Intercept
var a=[1,2,3,4,5,6];
var b=a.slice ( -1); [6]
///When only one parameter is passed, and the absolute value of the parameter is greater than the length of the array, the entire array
var a=[1,2,3,4,5,6] is intercepted;
var b=a.slice ( -6); [1,2,3,4,5,6]
var c=a.slice ( -8); [1,2,3,4,5,6]
///When two parameters are passed in a positive or negative, length will be added before the negative number, then intercept
var a=[1,2,3,4,5,6];
var b=a.slice (2,-3); [3]
///When passing in a parameter that is greater than length, an empty array of
var a=[1,2,3,4,5,6] is returned;
var b=a.slice (6); //[]
2.slice (String)
Usage: String.slice (start,end)
Explanation: The slice method copies part of a string to construct a new string, as in the slice method of the parameter blend array; the end parameter equals the position value of the last character you want to take, plus 1.
Give a simple example of
var a= "I am a boy";
var b=a.slice (0,6); "I am a"
3.splice (Array)
Usage: Array.splice (Start,deletecount,item ...)
Explanation: The Splice method removes one or more arrays from the array and replaces them with the new item. Parameter start removes the starting position of an element from the array of arrays. The parameter deletecount is the number of elements to remove.
If there are additional parameters, the item is inserted in the position where the element is removed. It returns an array containing the removed elements.
Give a simple example of
var a=[' A ', ' B ', ' C ';
var b=a.splice (1,1, ' e ', ' f '); A=[' A ', ' e ', ' f ', ' C '],b=[' B '
4.split (String)
Usage: string.split (separator,limit)
Explanation: The Split method splits the string into fragments to create an array of strings. Optional parameter limit can limit the number of fragments that are fragmented. The separator parameter can be a string or a regular expression. If
Separator is an empty character that returns an array of single characters.
Give a simple example of
var a= "0123456";
var b=a.split ("", 3); b=["0", "1", "2"]
The above is the entire content of this article, I hope to help you learn.