Skip to content

Instantly share code, notes, and snippets.

@Ref-Bit
Created December 31, 2020 12:25
Show Gist options
  • Save Ref-Bit/4c3f1e7e50b0cb5be0bdcd867eed5976 to your computer and use it in GitHub Desktop.
Save Ref-Bit/4c3f1e7e50b0cb5be0bdcd867eed5976 to your computer and use it in GitHub Desktop.
Remove a property without mutating the object
const car = {
color: 'blue',
brand: 'Ford'
}
const prop = 'color';
const newCar = Object.keys(car).reduce((object, key) => {
if (key !== prop) {
object[key] = car[key]
}
return object
}, {})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment