Definition and usage of the split () method:
The split () method splits the string into an array of strings using the substring of the string as a delimiter, and returns the array.
Note: The substring as a delimiter does not become part of the element of the returned array or a member of the array element.
This only describes using ordinary characters as delimiters, and you can refer to the regular expression split () function section with regular expressions as delimiters.
Click to see more related string object methods and properties.
Syntax structure:
Copy Code code as follows:
Stringobject.split (Separator,limit)
Parameter list:
Parameters |
Describe |
Separator |
Necessary. The substring used to split the string. Note : If this parameter is an empty string "", then each character in the Stringobject will be split |
Limit |
Optional. Sets the number of times the string is split, and if this argument is omitted, the number of splits is not limited. |
Note: If this parameter is an empty string "", then each character in the Stringobject will be split
Limit optional. Sets the number of times the string is split, and if this argument is omitted, the number of splits is not limited.
Instance code:
Copy Code code as follows:
var a= "A, B, C, D, E";
Console.log (A.split (","));
Use the substring "," as the delimiter to split the string, which does not become part of an array element or a member of an array element. Output result: A,b,c,d,e.
Copy Code code as follows:
var a= "A, B, C, D, E";
Console.log (A.split (",", 2));
The number of times a string is delimited, which limits the number of dimensions that return an array. Output Result: 2.
Copy Code code as follows:
var a= "A, B, C, D, E";
Console.log (A.split (""));
With an empty string as the delimiter, each character in the string is split. Output result: a,、, b,、, c,、, d,、, E.
The above content is small to introduce the JavaScript Split () method of knowledge, I hope you like.