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

389
Views
How to determine whether an array object has a value, and then return the array of objects with this value,

How to determine whether an array object has a value, and then return the array of objects with this value. Because I'm a novice, Similar to fuzzy search, give an example:

const menu = [
  {
    title: "one",
    secondLevel:{
      name:"hellobye",
      children: [{name: "hello"}, {name: "bye"}],
   }
 },
  {
    title: "two",
    secondLevel:{
      name:"level",
      children: [{name: "good"}, {name: "night"}],
   }
 }
]
  1. Assume input "go", the result should be:
menu = [
   {
    title: "two",
    secondLevel:{
      name:"level",
      children: [{name: "good"}, {name: "night"}],
   }
 }
]
about 4 years ago · Santiago Gelvez
1 answers
Answer question

0

If that object structure is consistent, then you can just do a filter with some and includes:

const menu=[{title:"one",secondLevel:{name:"hellobye",children:[{name:"hello"},{name:"bye"}],}},{title:"two",secondLevel:{name:"level",children:[{name:"good"},{name:"night"}],}}];

const filterBy = toFilter => {
  return menu.filter(({ secondLevel }) => secondLevel.children.some(({ name }) => name.includes(toFilter)));
};

console.log(filterBy("go"));
console.log(filterBy("ll"));
.as-console-wrapper { max-height: 100% !important; top: auto; }

about 4 years ago · Santiago Gelvez 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!