Skip to content

Instantly share code, notes, and snippets.

@rmrotek
Last active January 16, 2019 17:28
Show Gist options
  • Select an option

  • Save rmrotek/ab70264529fa37e59371882081f575df to your computer and use it in GitHub Desktop.

Select an option

Save rmrotek/ab70264529fa37e59371882081f575df to your computer and use it in GitHub Desktop.
Removes specified key from obj
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