- separator (optional): a string or Regular Expression. If no separator is specified, the entire string becomes one array element. If the delimiter is the empty string (''), the split() method will return an array where each character is an array element
- limit (optional): an integer indicating the number of splits. The rest of the elements will be discarded.
Split string using a space separator
Split string using a comma separator
Split multiline string into separate lines
Split a string into separate characters
Limiting the number of splits
Split string into a specified number of substrings
Split string using Regular Expression
Split strings by capital letters using Regular Expression
The following is an example of splitting a string by capital letters using the split() method and specifying a Regular Expression as the delimiter:
Split a string using an array of delimiters
The following is an example of splitting a string using an array of delimiters:
The array.join() method is the opposite of the string.split() method. The main difference between the join() and split() methods is that the join() method is used to concatenate array elements into a string, while the split() method is used to split a string into an array using a delimiter.