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

15th Jan 2021, 10:51 AM
harshit
harshit - avatar
5 Réponses
15th Jan 2021, 11:02 AM
Zohaib 👑
Zohaib 👑 - avatar
+ 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
15th Jan 2021, 5:11 PM
maf
maf - avatar
0
You can split your sentence into array. var array = entry.split(" "); Then loop over the array to find the exact word. 🚀
15th Jan 2021, 10:55 AM
Zohaib 👑
Zohaib 👑 - avatar
0
Zohaib 👑 any simple example ?
15th Jan 2021, 10:56 AM
harshit
harshit - avatar
0
var n = str.split(' ').includes("Fu");
15th Jan 2021, 4:29 PM
visph
visph - avatar