Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

404
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda