I'm using typescript (angular2) to create a "reset" method on an object array:
cars [
{
id: 1,
color: white,
brand: Ford,
model: Mustang,
...
},
...
]
User can modify this objects, and he can also "reset" to default values. So I keep an array of objects called originalCars. So if he selects the first object and choose "reset", I want to do something like: car = originalCar.
I was doing this:
this.selectedCars().map(car=> {
const originalCar = this.getOriginalCar(car.id);
car.color = originalCar.color;
car.brand = originalCar.brand;
// ... I'm doing this to all properties of my object
});
This is working, but I want to do it simple. Something like car = originalCar. I tried:
this.selectedCars().map(car=> {
const originalCar = this.getOriginalCar(car.id);
return originalCar;
// also tried car = originalCar;
});
The selectedCars method is:
selectedCars = () => {
return this.cars.filter(car=> {
return car.selected;
});
};
But It did not work. How can I do this?