Skip to content

Instantly share code, notes, and snippets.

View gerardcarbo's full-sized avatar

Gerard Carbó gerardcarbo

View GitHub Profile
@tjmehta
tjmehta / javascript-object-to-querystring.js
Last active October 31, 2024 23:25
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('');
}, '');
}