Skip to content

Instantly share code, notes, and snippets.

@jonathan-fielding
Created February 17, 2021 19:42
Show Gist options
  • Save jonathan-fielding/8e19ee0fe1ab2bfab84a36f62006ff86 to your computer and use it in GitHub Desktop.
Save jonathan-fielding/8e19ee0fe1ab2bfab84a36f62006ff86 to your computer and use it in GitHub Desktop.
function omit(obj, omitList = []) {
const result = { ...obj };
omitList.forEach((prop) => {
delete result[prop];
});
return result;
}
const person = {
name: 'Jonathan',
age: 21,
gender: 'male'
}
const ageOmitted = omit(person, ['age']);
console.log(ageOmitted); // Result { name: 'Jonathan', gender: 'male' }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment