Created
February 6, 2019 14:29
-
-
Save splosch/ae21fe17f22794c7c3ef2bd3b39a9403 to your computer and use it in GitHub Desktop.
This file contains 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
// allow Object.values(myObject) for IE | |
// alternative in a npm controlled environment: https://www.npmjs.com/package/object.values | |
Object.values = Object.values ? Object.values : function(obj) { | |
var allowedTypes = ["[object String]", "[object Object]", "[object Array]", "[object Function]"]; | |
var objType = Object.prototype.toString.call(obj); | |
if(obj === null || typeof obj === "undefined") { | |
throw new TypeError("Cannot convert undefined or null to object"); | |
} else if(!~allowedTypes.indexOf(objType)) { | |
return []; | |
} else { | |
// if ES6 is supported | |
if (Object.keys) { | |
return Object.keys(obj).map(function (key) { | |
return obj[key]; | |
}); | |
} | |
var result = []; | |
for (var prop in obj) { | |
if (obj.hasOwnProperty(prop)) { | |
result.push(obj[prop]); | |
} | |
} | |
return result; | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment