There is a function that changes the key "certificate" to "certificate_car". Is there a way to improve the function by using directly the assign method to change the array? Is it possible?
const arr = [{
"name": "BMW",
"price": "55 000",
"country": "Germany",
"certificate": "yes"
},
{
"name": "Mercedes-benz",
"price": "63 000",
"country": "Germany",
"certificate": "yes"
},
{
"name": "Mitsubishi",
"price": "93 000",
"constructor": "Bar John",
"door": "3",
"country": "Japan",
},
{
"name": "TOYOTA",
"price": "48 000",
"max_people": "7",
"country": "Japan",
"certificate": "yes"
},
{
"name": "Volkswagen",
"price": "36 000",
"constructor": "Pier Sun",
"country": "Germany",
"certificate": "no"
},
];
function certificateCar(arr) {
return arr.map(function(item) {
let itemCar = {};
let newItem = Object.assign({}, item);
Object.keys(newItem).forEach(item => {
itemCar[item.replace("certificate", "certificate_car")] = newItem[item]
});
return itemCar;
})
}
console.log(certificateCar(arr))