- Instant help with your JavaScript coding problems

Split a string into words

Question:
How to split a string into words?
Answer:
let text = 'This is a text with multiple words';

let words = text.split(' ');

console.log('Words: ', words);
Description:

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.

Reference:
split reference
Share "How to split a string into words?"
Tags:
divide string, split string, divide string to array, split string to array, divide, split, string, array
Technical term:
Split a string into words