These are the two objects:
const discount = {
rate: 0.50,
reason: 'New Year Sales'
}
const products = [
{
name: 'TV',
price: '1200'
},
{
name: 'Bed',
price: '500'
},
{
name: 'Table',
price: '50'
}
]
I want to get them into a new object:
const newProducts = [
{
name: 'TV',
price: '1200',
rate: 0.50,
reason: 'New Year Sales',
finalPrice: 600
},
{
name: 'Bed',
price: '500',
rate: 0.50,
reason: 'New Year Sales',
finalPrice: 250
},
{
name: 'Table',
price: '50',
rate: 0.50,
reason: 'New Year Sales',
finalPrice: 25
}
]
This is a JavaScript exercise and I have tried 'Object.assign' but the new value will overwrite the old ones, resulting in only the newest available. I am not sure whether destructuring using {...products} along with map, forEach will be of use. I can't make this happen