Last updated on Sep 15, 2021 by Suraj Sharma
In this tutorial, you’ll learn how you can split a sentence into words in JavaScript using the split()
method.
To divide a string into words you can use the string.split()
method and pass a whitespace as an argument to the split()
method. It returns an array of words.
const sentence = "Split a sentence into words in JavaScript";
sentence.split(" ");
// ["Split", "a", "sentence", "into", "words", "in", "JavaScript"]
Related Solutions
Rate this post
Suraj Sharma is the founder of Future Gen AI Services. He holds a B.Tech degree in Computer Science & Engineering from NIT Rourkela.