Definition and usage of split() method:
Thesplit() method can use the substring of the string as a delimiter to split the string into a string array and return this array.
Note: The substring used as a delimiter will not become part of the elements of the returned array or a member of the array elements.
Here we only introduce the use of ordinary characters as separators. For information on using regular expressions as separators, please refer to the regular expression split() function chapter.
Click to see more related String object methods and properties.
Grammar structure:
Parameter list:
Note: If this parameter is an empty string "", then each character in stringObject will be split
limit is optional. Set the number of times the string is divided. If this parameter is omitted, there is no limit to the number of times the string is divided.
Example code:
Use the substring "," as the delimiter to split the string. This delimiter will not become part of the array element or a member of the array element. Output results: a, b, c, d, e.
Limits the number of string splits, which also limits the dimensions of the returned array. Output result: 2.
Use an empty string as the delimiter, then each character in the string will be split. Output results: a,,,b,,,c,,,d,,,e.
The above content is the relevant knowledge of the JavaScript Split() method introduced by the editor. I hope you like it.