Copyright 2025

The Valley of Code

A Flavio Copes project

How to cut a string into words in JavaScript
How to cut a string into words in JavaScript

Use the split() method of a string instance. It accepts an argument we can use to cut the string when we have a space:

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

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

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

Want to master TypeScript? Check out my TypeScript Masterclass

Join my AI Workshop !

The Web Development BOOTCAMP cohort starts in February 2026