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

219
Vistas
Cómo filtrar elementos en una matriz de objetos según el elemento en la matriz de propiedades en JavaScript

¿Cuál es la mejor manera de devolver elementos en una matriz de objetos si contienen una determinada propiedad en una propiedad que es una matriz?

Tengo la siguiente matriz de objetos:

 const menus = [ { id: 1, title: 'English', locations: ['MENU', 'MENU_EN'] }, { id: 2, title: 'Spanish', locations: ['MENU', 'MENU_SP'] }, { id: 3, title: 'German', locations: ['MENU', 'MENU_DE'] }, { id: 4, title: 'German and english', locations: ['MENU', 'MENU_EN', 'MENU_DE'] }, ]

Como ejemplo, estoy buscando una forma de devolver cualquier elemento que tenga 'MENU_EN' en la propiedad de ubicaciones. Así que necesito una función que devuelva lo siguiente:

 const filteredMenus = [ { id: 1, title: 'English', locations: ['MENU', 'MENU_EN'] }, { id: 4, title: 'German and english', locations: ['MENU', 'MENU_EN', 'MENU_DE'] }, ]
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Puede filtrar la matriz de menus usando Array.prototype.filter() verificando si la propiedad de ubicaciones incluye el MENU_EN deseado con Array.prototype.includes() :

Código:

 const menus = [{id: 1,title: 'English',locations: ['MENU', 'MENU_EN']},{id: 2,title: 'Spanish',locations: ['MENU', 'MENU_SP']},{id: 3,title: 'German',locations: ['MENU', 'MENU_DE']},{id: 4,title: 'German and english',locations: ['MENU', 'MENU_EN', 'MENU_DE']},] const filteredMenus = menus.filter(({ locations }) => locations.includes('MENU_EN')) console.log(filteredMenus)

about 4 years ago · Juan Pablo Isaza 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