About the use of JS split is not much else to say what, the following direct examples for everyone to see
Copy Code code as follows:
<script language= "JavaScript" >
Str= "2,2,3,5,6,6"; This is a string
var strs= new Array (); Define an array
Strs=str.split (","); Character segmentation
for (i=0;i<strs.length; i++)
{
document.write (strs[i]+ "<br/>"); Character output after segmentation
}
</script>
The output result is
2
2
3
5
6
6
JS Split is a string to a specific character into a number of strings, we should be a look to understand it.
The following is about the definition and usage of JS split, official reference.
Definitions and usage
The split () method is used to split a string into an array of strings.
Grammar
Stringobject.split (Separator,howmany)
Parameter description
Separator required. A string or regular expression that splits the Stringobject from the place specified by the parameter.
Howmany Optional. This parameter specifies the maximum length of the array to return. If this argument is set, the returned substring will not be more than the array specified by this parameter. If this argument is not set, the entire string is split, regardless of its length.
return value
An array of strings. The array is created by splitting the string stringobject into substrings at the boundary specified by separator. The string in the returned array does not include the separator itself.
However, if separator is a regular expression that contains a subexpression, the returned array includes a string that matches the subexpression (but does not include text that matches the entire regular expression).