Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

222
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!