Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

220
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda