JavaScript split a sentence into words | Example code

Just use the split method to split a sentence into words in JavaScript. You can also use it for loop iteration. In both ways, you have to use the space option for separating normal sentences.

JavaScript split the sentence into words Example code

HTML example code:-

Using split method

It will return array without space.

Output: Return value be in Array.

JavaScript split a sentence into words array

Using for loop

Output: Result will be same for both example. But you can notice in this example have space after every word.

js split a sentence into words example

Do comment if you have nay doubts and suggestions on this basic JS question based topic and example code.

Note: All JS Examples codes are tested on the Firefox browser and the Chrome browser.
OS: Windows 10
Code: HTML 5 Version


Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.