Get the first word of string JavaScript | Example code

Use split method with 0 index to get the Get the only first word of string in JavaScript. Split method return an array, so you can easily get first element.

Get the first word of string JavaScript example

HTML example code:

You need to split the string by space and the get only 0 index value.


Do comment if you have any doubts and suggestions on this JS string topic.

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.