Skip to content

Instantly share code, notes, and snippets.

@zplume
Created January 8, 2020 11:00
Show Gist options
  • Save zplume/62c7cb1746993c4bc6ad96cdb0b2d63b to your computer and use it in GitHub Desktop.
Save zplume/62c7cb1746993c4bc6ad96cdb0b2d63b to your computer and use it in GitHub Desktop.
function objectToQueryString(paramsObject) {
return Object.keys(paramsObject).reduce((accumulator, currentKey) => {
const prefix = accumulator === "" ? "?" : "&";
return `${accumulator}${prefix}${currentKey}=${encodeURIComponent(paramsObject[currentKey])}`;
}, "");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment