Last active
January 16, 2019 17:28
-
-
Save rmrotek/ab70264529fa37e59371882081f575df to your computer and use it in GitHub Desktop.
Removes specified key from obj
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
| var user = { | |
| "id": 1, | |
| "name": "Leanne Graham", | |
| "username": "Bret", | |
| "email": "[email protected]", | |
| "address": { | |
| "street": "Kulas Light", | |
| "suite": "Apt. 556", | |
| "city": "Gwenborough", | |
| "zipcode": "92998-3874", | |
| "geo": { | |
| "lat": "-37.3159", | |
| "lng": "81.1496" | |
| } | |
| }, | |
| "phone": "1-770-736-8031 x56442", | |
| "website": "hildegard.org", | |
| "company": { | |
| "name": "Romaguera-Crona", | |
| "catchPhrase": "Multi-layered client-server neural-net", | |
| "bs": "harness real-time e-markets" | |
| } | |
| } | |
| function removeKey(obj, keys){ | |
| return Object.keys(obj) | |
| .filter(k=> k != keys) | |
| .map(k=> Object.assign({}, {[k]: obj[k]})) | |
| .reduce((res, o) => Object.assign(res, o), {}); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment