Syntax of the Split Method in JavaScript
Following is the syntax of split() method:
Where:
- separator (optional): the string or Regular Expression is used to split the string. If no delimiter is specified, the entire string becomes one array element. If the separator is the empty string (''), each character of the string is separated
- limit (optional): an integer indicating the number of splits in the given string. If a string remains unchecked after the limit is reached, it is not displayed in the array
Split Method Examples in JavaScript
Below you can see more examples splitting a string in JavaScript:
Split string to character array
Split string by space
Limiting the number of splits
Split string using a comma separator
Split string using Regular Expression
Split strings by capital letters using Regular Expression
Split string using a slash as a separator
Split a string using an array of different delimiters
How to convert array to string in JavaScript?
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.