Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
const buildQueryString = (params) => {
let parts = [];
let add = (key, value) => {
parts.push(encodeURIComponent(key) + '=' + encodeURIComponent(value));
}
for (let key in params) {
let param = params[key];
if (Array.isArray(param)) {
param.map((value) => {
add(key, value);
});
}
else {
add(key, param);
}
}
return '?' + parts.join('&').replace(/%20/g, '+');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.