Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

186
Views
How to do spelling check with each of the property of an array of Object?

I am developing a program where a user will pass an argument and the program will give almost the same match of the result that it will find in an array of Object. So I have an array of object which is coming from a database so when my user will pass a name the search criteria on the array of object should work something like this suppose the user have passed a name called Jack Ma now on my array there are following objects like

[
{
name: "Jacky Ma"
},
{
name: "Jacky Man"
},
{
name: "Jack Mun"
},
{
name: "Jacob Ma"
},
{
name: "Jack Ma"
}
]

so for this following case Jacky Ma, Jack Mun, Jacob Ma should get retuned in an array of object. Only thing the program should check is the spelling of the each words matches with spelling of the words that are in the object lowerCase upperCase do not matter here for both words or if there is one or more than 2. The only thing it should check is the spelling of the words if the first word spelling matches with the spelling of the first word or 2nd word spelling matches with 2nd word of the object only then it should return. If neither or one do not get matched it should return empty array.

can anyone help me how can I do this ? Thanks in Advance.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

In your current code, you are comparing the whole String "Jack Ma" and not "Jack" and "Ma". You need to split the name property and the string, loop over them and compare:

const filterData = searchClan.items.filter(
    n => {
        const splittedName = n.name.toLowerCase().split(' ');
        const splittedArgs = validateArgs.toLowerCase().split(' ');
        return splittedArgs.some((argument, index) => splittedName[index] && splittedName[index] === argument)
    });

The "some" method returns true if one of the element (at index "index" ) in the splittedArgs array matches with the element at index "index" in the splittedName array.

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!