Is there a clean way to return a new object that omits certain properties that the original object contains without having to use something like lodash?
Remove Property from an ObjectThe delete operator deletes both the value of the property and the property itself. After deletion, the property cannot be used before it is added back again. The delete operator is designed to be used on object properties. It has no effect on variables or functions.
To remove a property from all objects in an array:Use the Array. forEach() method to iterate over the array. On each iteration, use the delete operator to delete the specific property. The property will get removed from all objects in the array.
The JavaScript delete operator removes a property from an object; if no more references to the same property are held, it is eventually released automatically.
Using the delete operator to remove a property The delete operator is used to remove the key from an object, and its key and value are removed from an object. Return true, if the key is removed, and return false if the key does not exist.
const { bar, baz, ...qux } = foo
Now your object qux
has all of the properties of foo
except for bar
and baz
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With