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

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