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

221
Vistas
Changing of values of keys in JSON

I have an application, where I use MongoDB, Express and MongoDB. On server side I received data by using find in such look - array of objects(JSON), which is named upProbations. For example, I find information about Max:

[        
  {
        Name: 'Max',
        DateOne: 2019-01-01T00:00:00.000Z,
        DateTwo: 2019-04-01T00:00:00.000Z,
        Info: 'Cheerful'
  }
]

I want to change information a bit - fields DateOne and DateTwo. They have both types Date and I want to leave only 2019-01-01 and same for DateTwo, so i don't need time(hour, minute, second). The result should look like this:

[        
  {
        Name: 'Peter',
        DateOne: 2019-01-01,
        DateTwo: 2019-04-01,
        Info: 'Cheerful'
  }
]

This result I will futher use for antoher calculations. I have tried such code, but it's not working:

upProbations = upProbations.map(function(a) {
    a.DateOne = a.DateOne.toISOString().replace('T', ' ').substr(0, 10);
return a;
})
console.log(upProbations);

In which way I can do this?

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

let upProbations = [
  {
    Name: "Max",
    DateOne: 2019-01-01T00:00:00.000Z,
    DateTwo: 2019-04-01T00:00:00.000Z,
    Info: "Cheerful",
  },
];

upProbations = upProbations.map((eachObject) => {
  const { DateOne, DateTwo, Name, Info } = eachObject;
  return {
    Name,
    DateOne: DateOne.toString().split("T")[0],
    DateTwo: DateTwo.toString().split("T")[0],
    Info,
  };
});

console.log(upProbations);

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