I am trying to search whether a string is present inside an array of strings using the string.includes() method as shown below
var theString = "clovers are the best";
var theArray = ["lovers", "loved", "clove", "love", "clovers"];
for (i = 0; i < theArray.length; i += 1) {
if (theString.includes(theArray[i])) {
console.log(theArray[i]);
}
}
The output I get includes "lovers", "clove" and "love" in addition to the expected "clovers." How can I force the search to look for entire string only?
===instead ofString.prototype.includestheArray[i].includes(theString)?theArray.includes(theString)with no loop..includes().