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

151
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar

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 Denunciar

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