Removing Property from an Object

December 28, 2023

DSA & Leetcodes

Removing Property from an Object

Thuta Sann

Thuta Sann

Removing Property from an Object by using Reduce Method


Share This Snippet To :

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);

Cookie

I baked some cookies that you have to accept, if you want to enjoy my portfolio.
In order to gather information and make improvements, I should use some third-party cookies too, Can I?