Immutable way to delete a key from an object
/* Returns object without the specified property
* Example: Cal.query = removeKey(Cal.query, 'AppointmentType');
*/
const removeKey = (obj, propToDelete) => {
const { [propToDelete]: deleted, ...objectWithoutDeletedProp } = obj;
return objectWithoutDeletedProp;
};
Written by Sophie Idromenos
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Javascript
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#