xrssxg
Last Updated: March 01, 2018
·
556
· techmsi

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