[Home] >  Object >  Omit a subset of properties from an object

Omit a subset of properties from an object

JavaScript version

const omit = (obj, keys) =>
Object.keys(obj)
.filter((k) => !keys.includes(k))
.reduce((res, k) => Object.assign(res, { [k]: obj[k] }), {});

Examples

omit({ a: '1', b: '2', c: '3' }, ['a', 'b']); // { c: '3' }