The usage of js split is nothing else. Let's take a look at the examples below.
Copy codeThe Code is as follows: <script language = "javascript">
Str = "2,2, 3,5, 6,6"; // This is a string
Var strs = new Array (); // defines an Array
Strs = str. split (","); // delimiter
For (I = 0; I <strs. length; I ++)
{
Document. write (strs [I] + "<br/>"); // delimiter output
}
</Script>
The output result is
2
2
3
5
6
6
Js split divides a string into multiple strings by specific characters. you should understand it at a glance.
The following is an official reference for the definition and usage of js split.
Definition and usage
The split () method is used to split a string into a string array.
Syntax
StringObject. split (separator, howator)
Parameter description
Separator is required. String or regular expression, which separates stringObject from the specified place.
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.
Return Value
A string array. This array is created by dividing the string stringObject into substrings at the boundary specified by separator. The strings in the returned array do not include the separator itself.
However, if separator is a regular expression that contains a subexpression, the returned array contains the strings that match the subexpression (but does not include the text that matches the entire regular expression ).