In my project using TypeScript (Angular 2), I am working on creating a "reset" method for an object array:
cars [
{
id: 1,
color: white,
brand: Ford,
model: Mustang,
...
},
...
]
Users have the ability to modify these objects, as well as reset them to their default values. To achieve this, I have created an array of objects called originalCars. When a user selects and chooses to "reset" the first object, I aim to execute something like: car = originalCar.
Initially, I attempted the following approach:
this.selectedCars().map(car=> {
const originalCar = this.getOriginalCar(car.id);
car.color = originalCar.color;
car.brand = originalCar.brand;
//... repeating this procedure for all properties of the object
});
While this method is functional, I desire a simpler solution. Something along the lines of car = originalCar. My attempt was as follows:
this.selectedCars().map(car=> {
const originalCar = this.getOriginalCar(car.id);
return originalCar;
// also tried car = originalCar;
});
The selectedCars method looks like this:
selectedCars = () => {
return this.cars.filter(car=> {
return car.selected;
});
};
Unfortunately, my attempts did not produce the desired outcome. Any suggestions on how I can simplify this process?