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

122
Visualizações
I can't replace the value of an array returned by mongoose

I have a notifications.find query (mongoose) that returns multiple sheets

Notification.find({id: id}, function(err, notifications){}

I need to convert the timestamp values that are returned like that

[                                                                                             
  {
    _id: new ObjectId("12934193c51a231b0165425a"),
    userid: '62921df1c14a2eea0efa9399',
    timestamp: 1653817696599,
  },
  {
    _id: new ObjectId("11934193c51a231b0165425a"),
    userid: '62921df1c14a2eea0efa9399',
    timestamp: 1653817696600,
  }
]

I tried this

notifications.forEach((element, index) => {

notifications[index].timestamp = new Date(notifications[index].timestamp);

});

and this code

new Date(notifications[index].timestamp);

seems to work by converting the timestamp of each value, but I can't replace it in the array

I've been on this issue for several hours

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Instead of forEach use map

const newNotifications = notifications.map((element, index) => {
  return {
    ...element,
    timestamp: new Date(element.timestamp),
   }
});
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