I am currently working on updating an object within an array and have encountered some issues. In my initial code, I successfully updated a specific property of the object inside the array like this:
var equipment = this.equipments.find((e) => e.id === this.currentItem.id);
// this property is getting updated successfully in the array
equipment.countryId = this.currentItem.countryId;
However, since the object has many properties, I attempted to use the spread operator to fully copy the object and update it with new values:
var equipment = this.equipments.find((e) => e.id === this.currentItem.id);
equipment = { ...equipment, ...this.currentItem };
Unfortunately, this approach did not work as expected. It seems that the spread operator creates a new object instead of updating the existing one in the array.
This raises the question: is there an alternative method to update all properties of an object with new values without explicitly defining each property?