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...