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

142
Views
How can I update / edit the value of objects in an array of objects?

So I have an array of objects from the api, which looks like this:

[{
    "title": "demo",
    "eventType": "demo",
    "start": "2022-06-26T07:00:00.000Z",
    "end": "2022-06-26T04:00:00.000Z"
...
},{}
]

I would like to create a new array with the same values but wrapping the start and end object values in a new Date() like this:

[{
    "title": "demo",
    "eventType": "demo",
    "start": new Date("2022-06-26T07:00:00.000Z"),
    "end": new Date("2022-06-26T04:00:00.000Z")
...
},{}
]
about 4 years ago · Juan Pablo Isaza
3 answers
Answer question

0

Use the map method on the array to loop over each object and return a modified object.

const result = data.map(({ start, end, ...rest }) => ({
  ...rest,
  start: new Date(start),
  end: new Date(end)
}));
about 4 years ago · Juan Pablo Isaza Report

0

var arrayA = [
    {
        "title": "demo",
        "eventType": "demo",
        "start": "2022-06-26T07:00:00.000Z",
        "end": "2022-06-26T04:00:00.000Z"
    }
];

var arrayB = [];

for (let index = 0; index < arrayA.length; index++) {
    var element = arrayA[index];
    element.start = new Date(element.start);
    element.end = new Date(element.end);
    arrayB.push(element);
    console.log(arrayB);
}
about 4 years ago · Juan Pablo Isaza Report

0

const demo = [{
    "title": "demo",
    "eventType": "demo",
    "start": "2022-06-26T07:00:00.000Z",
    "end": "2022-06-26T04:00:00.000Z"
}]
demo.map(obj => ({...obj,start:new Date(obj.start),end:new Date(obj.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!