How to cut a string into words in JavaScript

Use split() method of string instance. It accepts a parameter, when we have spaces, we can use this parameter to cut the string:

const text = "Hello World! Hey, hello!"
text.split(" ")

The result is an array. In this case, an array containing 4 items:

[ 'Hello', 'World!', 'Hey,', 'hello!' ]  

More js tutorials: