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

64
Visualizações
The new array is receving only the last item of forEach loop

I'm trying to manipulate different arrays, so there's an original array, there's a JSON object model that the new array needs to be populated by this object model, and I need to transform the original array data into this new array, but for some reason when I try to push the new object into the new array, only the last item is pushed and repeated all the way, as follows:

this.customersTable.forEach((costumer) => {
      const newObj = this.objModel;
      Object.keys(newObj).map((key) => {
        newObj[key] = costumer[key];
        if (newObj[key] === undefined || newObj[key] === null) {
          newObj[key] = '';
        }
      });
      this.exportData.push(newObj); this.exportData is any[] type
      console.log(newObj);
      console.log(this.exportData)
});

This id: 6898 is the last item of the original array, but as you can see the object that is being pushed into this new array is correct...

about 4 years ago · Juan Pablo Isaza
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