slice of splice of split of substring of substr of
- 2020-05-16 06:14:24
1. slice ();
Both Array and String objects are available
In Array slice (i, [j])
i is the index value intercepted at the beginning, the negative value represents the index value calculated from the end, and -1 is the last element from the end
j is the end index value, and by default gets all elements from i to the end
Returns an array of index values from i to j, unchanged
In String slice (i, [j])
i is the index value intercepted at the beginning, the negative number represents the index value calculated from the end, and -1 is the last character from the end
j is the end index value, and by default gets all characters from i to the end
2. splice ()
There are methods in Array that add/delete items to/from the array, and then return the deleted items. This method changes the original array
index: required. An integer specifying the location of the add/remove item, and a negative number specifying the location from the end of the array.
howmany: required. The number of items to delete. If set to 0, the project will not be deleted.
item1... itemX: optional. The new item added to the array.
The return value Array contains a new array of deleted items, if any.
3. split ()
In String, split (separator, howmany)
separator: required. A string or regular expression that splits stringObject from where this parameter is specified.
howmany: optional. This parameter specifies the maximum length of the returned array. If this parameter is set, no more substrings are returned than the array specified by this parameter. If this parameter is not set, the entire string is split regardless of its length.
The return value
1 array of strings. The array is created by splitting the string StringObject into substrings at the boundary specified by separator. The string of the returned array does not contain separator itself
However, if separator is a regular expression that contains subexpressions, then the array returned contains strings that match those subexpressions (but not the text that matches the entire regular expression)
The opposite effect to the jion () function
4. substring ()
In String substring (start stop)
start: represents the starting position of the substring,
stop: indicates the end result.
Note: the second parameter should be greater than the first parameter. If the first parameter is greater than the second, the substring method automatically changes the positions of the two parameters.
5. substr ()
In String, substr (start, length);
start: the starting position of the substring,
length: length of the substring.
That's all for this article, I hope you enjoy it.