Created
December 29, 2011 14:02
-
-
Save willywongi/1534226 to your computer and use it in GitHub Desktop.
Return a new object from an array of key/value pairs
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
/** | |
* Return a new object from an array of key/value pairs. | |
* Inspired by the "dict" constructor in python. | |
* | |
* @method dict | |
* @param {Array} arr An array of key/value pairs. | |
* @return {Object} A new object | |
* @static | |
*/ | |
Y.namespace('Object').dict = function(arr) { | |
for (var o = {}, i = 0, l = arr.length; i<l; i++) { | |
o[arr[i][0]] = arr[i][1]; | |
} | |
return o; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment