Last active
November 23, 2016 15:01
-
-
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
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
| //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