Exact word in a sentence: JavaScript | Sololearn: Learn to code for FREE!

0

Exact word in a sentence: JavaScript

includes() also checks of substring of a word but I want to find only exact full word is present or not. https://code.sololearn.com/WnrPuIHE7REP/?ref=app

1/15/2021 10:51:16 AM

harshit

5 Answers

New Answer

+1

harshit check here https://code.sololearn.com/W8J4AJWDQ3Lu/?ref=app

+1

first split all the words into an array const words = "Full Word".split(" ") // this will split the phrase from where ever it finds " ", i.e. a space. So now, words is equal to [ "Full", "Word" ] let found = false // use appropriate variable names, such as found. // 'includes' also works on arrays, and it doesn't match the substrings when used with array. if (words.includes("Fu")) found = true document.getElementById("demo").innerHTML = found

0

You can split your sentence into array. var array = entry.split(" "); Then loop over the array to find the exact word. 🚀

0

Zohaib 👑 any simple example ?

0

var n = str.split(' ').includes("Fu");