Get word from string JavaScript | Extract a specific word example

Use split and some function or regex with word boundaries to find or Extract a specific word from string in JavaScript.

Get word from string JavaScript Example

HTML example code: Match if word present in given string.

Using split and some function

If word found then return true.

Using a regex with word boundaries:

Output:

Get word from string JavaScript

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

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


One thought on “Get word from string JavaScript | Extract a specific word example

  1. ‘use strict’
    let str=’Remove the last word.’
    const findWord = (word) =>{
    return str.split(‘ ‘).some((w)=>w===word)===true?The word '${word}' is found:The word '${word}' is not found
    }
    console.log(findWord(‘last’))

Leave a Reply

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