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
javascript remove blank object

i have an array of objects that looks like: (obfuscated values)

[
  {
    "title": "l",
    "data": [
      {
        "id": "x",
        "bodyPart": "x",
        "equipment": "x",
        "gifUrl": "h",
        "name": "x",
        "target": "x",
        "broad_target": "x",
        "ppl": "p",
        "thumbnail": "h",
        "heatmap_target": "u"
      }
    ]
  },
  {}
]

if you notice, there is a blank {}.

my attempt to remove these is:

const cleanEmpty = obj => Object.entries(output)
                    .map(([k,v])=>[k,v && typeof v === "object" ? cleanEmpty(v) : v])
                    .reduce((a,[k,v]) => (v == null ? a : (a[k]=v, a)), {});

this does not work.

about 4 years ago · Santiago Gelvez
1 Respuestas
Responde la pregunta

0

you can use Array.filter to filter the blank objects like this :

const arr = [
  {
    foo: "bar"
  },
  {}
]

const newArr = arr.filter(obj => Object.keys(obj).length >= 1)

console.log(newArr) //[{foo: "bar"}]
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