Use the split() method of a string instance. It accepts an argument we can use to cut the string when we have a space:
使用字符串实例的split()方法。 它接受一个参数,当有空格时,我们可以使用该参数来剪切字符串:
const text = "Hello World! Hey, hello!"
text.split(" ")
The result is an array. In this case, an array with 4 items:
结果是一个数组。 在这种情况下,包含4个项目的数组:
[ 'Hello', 'World!', 'Hey,', 'hello!' ]
翻译自: https://flaviocopes.com/how-to-cut-string-words-javascript/