In this Snippet, I will demonstrate Removing Property from an Object using Reduce Method.
const sampleObj = {
displayName: {
name: "Display Name",
field: "displayName",
},
firstName: {
name: "First Name",
field: "firstName",
},
lastName: {
name: "Last Name",
field: "lastName",
},
};
const keyToFilter = "lastName";
const filteredObject = Object.keys(sampleObj).reduce((acc, key) => {
if (key !== keyToFilter) {
acc[key] = sampleObj[key];
}
return acc;
}, {});
console.log("filteredObject", filteredObject);