Split a string into words
let text = 'This is a text with multiple words';
let words = text.split(' ');
console.log('Words: ', words);
The split()
method divides a String into an ordered list of substrings, puts these substrings into an array, and returns the array. The division is done by searching for a pattern; where the pattern is provided as the first parameter in the method's call.
When found, separator is removed from the string, and the substrings are returned in an array.
If separator is a regular expression with capturing parentheses, then each time separator matches, the results (including any undefined results) of the capturing parentheses are spliced into the output array.
If the separator is an array, then that Array is coerced to a String and used as a separator.
- Convert string to int in JavaScript
- Convert string to lowercase with JavaScript
- Capitalize words in a string using JavaScript
- Generate random string in JavaScript
- Generate UUID in JavaScript
- Convert string to kebab case in JavaScript
- Generate random color with JavaScript
- Convert snake case to camel case in JavaScript
- Convert string to character array in JavaScript
- Convert camel case to snake case in JavaScript
- Remove accents from a string in JavaScript
- Convert a string to sentence case in JavaScript
- Convert string to title case in JavaScript
- Convert string to snake case in JavaScript
- Convert string to pascal case in JavaScript
- Convert string to camel case in JavaScript
- Convert string to uppercase with JavaScript
- Convert object to JSON string in JavaScript
- Parse JSON string in JavaScript
- convert number to string in JavaScript
- Use colors in JavaScript console
- Get string length in JavaScript
- Split a string into words
- Replace line break with br in JavaScript
- Replace spaces with dashes in JavaScript
- Create multiline string in JavaScript