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

137
Views
filtrado profundo en una matriz de objetos

Tengo datos como este a continuación.

 let data = [ { name: 'basic', to: 'aaa', subMenus: [ { name: 'general conc', to: 'geneal', }, { name: 'example view', to: 'example', }, { name: 'fancy', to: 'bbb', innerSubMenus: [ { name: 'adding', to: 'add', }, { name: 'getting', to: 'get', }, ] } ] } ]

Necesito filtrar datos según el nombre (en main, subMenus e innerSubMenus) Aquí está el fragmento de código

 function deepFilter(inputText){ data.filter(items => items.name.toLowerCase().includes(inputText.toLowerCase())) }

Como puede ver, la función filtra el primer accesorio (nombre --> básico en este caso cuando inputText = 'basic', no funciona cuando inputText = 'general conc') pero quiero poder filtrar nombres en submenús y innerSubMenus también. Por favor, orienteme sobre como hacerlo. Gracias

resultados esperados:

 deepFilter('basic') -> true // only this part is covered by my implementation deepFilter('general conc') -> true deepFilter('adding') -> true deepFilter('ffff') -> false //since there is not name with value of 'ffff' in data
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Creo que esto debería funcionar bien.

 function deepFilter(inputText, datas) { return datas.filter(data => { function checkInsideObj(object, inputText) { for (let value of Object.values(object)) { if (object.name && object.name.toLowerCase() === inputText.toLowerCase()) { return true; } if (Array.isArray(value)) { return value.some(item => { return checkInsideObj(item, inputText) } ) } } return false; } return checkInsideObj(data, inputText) } ) } deepFilter("input", data)
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!