Home > Enterprise >  Searching by part of a word should return the word in js
Searching by part of a word should return the word in js

Time:07-25

so the problem I'm facing here is that I have an array of countries, what I want to do is when a user searches something like grmny or Grmny it could figure out that the user is trying to find Germany and bring out that object.

what I'm currently doing is:

const FilterByCountry = (countries, regionName) => {
    return countries.filter(country =>
        country.region
            .toLowerCase()
            .includes(regionName.toLowerCase())
    );
}

which works fine when the user types the word correctly, but it doesn't work on misspells mentioned above.

CodePudding user response:

What you're looking for is the so-called "fuzzy search". You may want to try this https://fusejs.io/

CodePudding user response:

I found a way to get what i want in another post, I'm gonna share the link below: https://stackoverflow.com/a/55338523/11589384

  • Related