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

217
Vistas
¿Cómo filtrar una matriz de objetos JavaScript?

Digamos que tengo el siguiente objeto

 var ob = [ { "id": 1, "comment": "some comment", "hidden": 0, }, { "id": 2, "comment": "some comment", "hidden": 1, }, { "id": 3, "comment": "some comment", "hidden": 1, }, { "id": 4, "comment": "some comment", "hidden": 0, } ]

¿Cómo puedo filtrar esto para decir, por ejemplo, devolver todo donde esté oculto = 1

Salud

about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

Utilice Array#filter :

 let arr = [ { "id": 1, "comment": "some comment", "hidden": 0, }, { "id": 2, "comment": "some comment", "hidden": 1, }, { "id": 3, "comment": "some comment", "hidden": 1, }, { "id": 4, "comment": "some comment", "hidden": 0, } ]; let res = arr.filter(x => x.hidden === 1); // or arr.filter(({hidden}) => hidden === 1); console.log(res);

about 4 years ago · Juan Pablo Isaza Denunciar

0

 var ob = [ { "id": 1, "comment": "some comment", "hidden": 0, }, { "id": 2, "comment": "some comment", "hidden": 1, }, { "id": 3, "comment": "some comment", "hidden": 1, }, { "id": 4, "comment": "some comment", "hidden": 0, }, { "id": 5, "comment": "some comment", "hidden": 2, } ] let result = ob.filter(x => x.hidden === 1); console.log("result for hidden properties 1",result) //Or you can use other condision. Just think like conditional operator but this is kind of different thing let result2 = ob.filter(x => x.hidden === 2); console.log("result for hidden properties 2",result2) //This condition only pass when hidden properties values 2. otherwise It won't filter and won't give your expected output , or result whatever you say.

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