Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save singhmohancs/89f355c120a56c303f49f1f645a7988d to your computer and use it in GitHub Desktop.
Save singhmohancs/89f355c120a56c303f49f1f645a7988d to your computer and use it in GitHub Desktop.
Object to Querystring - JavaScript, JS, JSON
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