I'm trying to develop a method to match words in array (fItems) with words from a string which has been converted into an Array (stringArray). The code I have below works most the time, but the trouble is that 'includes()' searches for patterns, rather than matching the whole word.
As an example. it gets confused if I'm looking for 'wall', and it returns 'wallet'. Also, I want the input to be flexible. So for instance, if glass is inputted, the item 'glass shard' is still returnable.
Is there are more precise way to match exact words?
for (let i = 0; i < db.items.length; i++) {
for (let j = 0; j < stringArray.length; j++) {
if (db.items[i].name.includes(stringArray[j])) {
fItems.push(db.items[i]);
};
}
};