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
5 Réponses
+ 1
+ 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");