let objArr = [
{ "name" : "mark", "height" : "tall", "hairColor": "black"},
{ "name" : "ben", "height" : "medium", "color": "fair"},
{ "name" : "neil", "height" : "small", "color": "dark"}
];
addmoreObject = {"gender": "male", "age": 33};
const res = objArr.map(({ hairColor, color, addmoreObject ...r }) => r);
console.log("RES", res)
I wanted to remove color and hairColor from object and wanted to add more element like gender, age etc. how can I make it in correct manner please guide
https://jsfiddle.net/v0yLu8m2/
>Solution :
You’re very close:
// Change
const res = objArr.map(({ hairColor, color, addmoreObject ...r }) => r);
// To
const res = objArr.map(({ hairColor, color, ...rest }) => {
return {
...rest,
...addmoreObject,
};
});