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

137
Views
how to remove a property from an array of objects

How to remove a property from an array of objects

need to be removed first _id, usedDays, put two arrays (start and end) into the one and deploy "user" in userId and name.

Have array:

[{
    "_id": "someID",
    "user": {
      "_id": "mongoID",
      "name": "Vasya"
    },
    "usedDays": 1,
    "start": "2021-07-02",
    "end": "2021-07-21"
  },
  {
    "_id": "someID",
    "user": {
      "_id": "mongoID",
      "name": "Ivan"
    },
    "usedDays": 5,
    "start": "2021-08-12",
    "end": "2021-08-22"
  }
]

Need array:

  [{
    "userId": "mongoID",
    "name": "Vasya"
    "partyDate": ["start": "2021-07-02","end": "2021-07-21"]
  },
  {
    "userId": "mongoID",
    "name": "Ivan"
    "partyDate": ["start": "2021-08-12","end": "2021-08-22"]
  }
]
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

I think Array.map is what you are looking for

array.map((item) => {
    return ({
        userId: item.user._id, 
        name: item.user.name, 
        partyDate: [{start: item.start, end: item.end}]
    })
})
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!