Created
September 28, 2013 12:12
-
-
Save xyqfer/6741463 to your computer and use it in GitHub Desktop.
Object to String
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
var obj2string = function( obj, prefix ) { | |
var str = []; | |
for ( var prop in obj ) { | |
if ( obj.hasOwnProperty( prop ) ) { | |
var k = prefix ? prefix + '[' + prop + ']' : prop, v = obj[prop]; | |
str.push( typeof v === 'object' ? | |
obj2string( v, k ) : | |
encodeURIComponent( k ) + '=' + encodeURIComponent( v ) ); | |
} | |
} | |
return str.join( '&' ); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment