Skip to content

Instantly share code, notes, and snippets.

@davidsharp
Last active November 23, 2016 15:01
Show Gist options
  • Select an option

  • Save davidsharp/760bba2024ae5e6a36983a1c3e09a501 to your computer and use it in GitHub Desktop.

Select an option

Save davidsharp/760bba2024ae5e6a36983a1c3e09a501 to your computer and use it in GitHub Desktop.
A `.map()`-based `Object.values` function, for when you need a shim but don't care about standards
//I have no idea whether this should be on `Object` or `Object.prototype`
Object.values=function(_obj){
return Object.keys(_obj)
.filter(function(k){return _obj.hasOwnProperty(k)&&_obj.propertyIsEnumerable(k)})
.map(function(k){return _obj[k]})
}
//And as an arrow function
Object.values= _obj => Object.keys(_obj).filter(k => _obj.hasOwnProperty(k)&&_obj.propertyIsEnumerable(k)).map(k => _obj[k])
//And if you're feeling wreckless (this is basically Object.keys(foobar).map(k=>foobar[k]))
Object.values=o=>Object.keys(o).map(k=>o[k])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment