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

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

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 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!