Exact word in a sentence: JavaScript | Sololearn: Learn to code for FREE!
Neuer Kurs! Jeder Programmierer sollte generative KI lernen!
Kostenlose Lektion ausprobieren
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 Antworten
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