Created
December 31, 2020 12:25
-
-
Save Ref-Bit/4c3f1e7e50b0cb5be0bdcd867eed5976 to your computer and use it in GitHub Desktop.
Remove a property without mutating the object
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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