Examples of Extracting First Word from a String
Table of Content
- Using split() Method
- Using substring() and indexOf() Methods
- Using Regular Expression
- Using slice() and indexOf() Methods
- Using for loop
- Using trim() and split()
JavaScript Program to Extract First Word from a String
In this article, we have to extract the first word from the input string in JavaScript language. Below is an example for better understanding.
Examples:
Input: Geeks for Geeks Output: Geeks Input: I Love India Output: I
Contact Us