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

283
Vistas
How to remove a object from a array of object based on a condition?

I have array of objects like this:

data = [
 {
   "name":"abc",
   "email":"abc@gmail.com"
 },
 {
   "name": "bcd",
   "email": "bcd@gmail.com",
   "info":[
     {
        "email": "bcd@gmail.com",
        "count":5
     }
     ]
 },
 {
    "name": "hfv",
    "email": "hfv@gmail.com",
    "info":[
      {
      "email": "hfv@gmail.com",
      "count":5
      },
      {
        "email": "hfv@gmail.com",
        "count":7
        }
      ]
  }
]

I want to to change data in such a way that only objects that have count>1 should exist

so the output should like this:

[{
   "name": "bcd",
   "email": "bcd@gmail.com",
   "info":[
     {
        "email": "bcd@gmail.com",
        "count":5
     }
     ]
 },
 {
    "name": "hfv",
    "email": "hfv@gmail.com",
    "info":[
      {
      "email": "hfv@gmail.com",
      "count":5
      },
      {
        "email": "hfv@gmail.com",
        "count":7
        }
      ]
  }
]

the data array should look like this, how I can I loop through this array of objects and remove objects that have count<=1?

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

0

You can use array.filter() to achieve it

const result = data.filter(obj => obj.info && obj.info.filter(info => info.count > 1).length > 0)

You may need to filter info objects as well... depends of your need. But you have everything you need here.

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