Forked from tjmehta/javascript-object-to-querystring.js
Created
March 1, 2019 01:33
-
-
Save carlosocarvalho/c7e7927bb6077abb6d15744a03fced22 to your computer and use it in GitHub Desktop.
Object to Querystring - JavaScript, JS, JSON
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
function objectToQuerystring (obj) { | |
return Object.keys.reduce(function (str, key, i) { | |
var delimiter, val; | |
delimiter = (i === 0) ? '?' : '&'; | |
key = encodeURIComponent(key); | |
val = encodeURIComponent(obj[key]); | |
return [str, delimiter, key, '=', val].join(''); | |
}, ''); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment