Home >Web Front-end >JS Tutorial >javascript String split method misoperation_javascript skills
split definition and usage
The split() method is used to split a string into a string array.
Syntax
stringObject.split(separator, howmany) Parameter Description
separator Required. A string or regular expression to split the stringObject from where specified by this parameter.
howmany optional. This parameter specifies the maximum length of the returned array. If this parameter is set, no more substrings will be returned than the array specified by this parameter. If this parameter is not set, the entire string will be split regardless of its length.
Return value
A string array. The array is created by splitting the string stringObject into substrings at the boundaries specified by separator. The strings in the returned array do not include the separator itself.
However, if separator is a regular expression containing subexpressions, then the returned array includes strings matching those subexpressions (but not text matching the entire regular expression).
Tips and Notes
Note: If an empty string ("") is used as a separator, each character in the stringObject will be split between them.
Note: The operation performed by String.split() is the opposite of the operation performed by Array.join.
In this example, we will split the string in different ways: