Skip to content

Instantly share code, notes, and snippets.

@splosch
Created February 6, 2019 14:29
Show Gist options
  • Save splosch/ae21fe17f22794c7c3ef2bd3b39a9403 to your computer and use it in GitHub Desktop.
Save splosch/ae21fe17f22794c7c3ef2bd3b39a9403 to your computer and use it in GitHub Desktop.
// 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