Created
November 2, 2012 13:48
-
-
Save altamic/4001472 to your computer and use it in GitHub Desktop.
javascript simple Array to Object conversion
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
> Array.prototype.toObject = function() {b={}; for(i=0;i<this.length;i+=2) {b[this[i]]=this[i+1]}; return b;} | |
[Function] | |
> ["chiave1","valore1","chiave2","valore2"].toObject() | |
{ chiave1: 'valore1', chiave2: 'valore2' } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment