Created
June 25, 2014 23:33
-
-
Save TastyToast/fa3876c0a4195ee069f1 to your computer and use it in GitHub Desktop.
Create Enum From Object
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
/** | |
* Creates and enum from the object based on key values | |
* | |
* @param {object} Object | |
* @return {object} enum from object | |
*/ | |
function buildEnumFromObject_(obj){ | |
var createdEnum = {}; | |
var i = 0; | |
for(var key in obj) { | |
if(!obj.hasOwnProperty(key)){ | |
continue; | |
} | |
var keyName = key.toUpperCase().replace | |
var keyName = key.toUpperCase().replace(/\s+/g, ''); | |
createdEnum[keyName] = i; | |
i = i + 1; | |
}; | |
return createdEnum; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment