To split string with white space with JavaScript, we use the split
method.
For instance, we write
const str = "my car is green";
const stringArray = str.split(/(\s+)/);
to call str.split
with a regex that matches whitespaces to split the str
string by the whitespaces and return an array with the split substrings.