Skip to content

Instantly share code, notes, and snippets.

@jcypret
Created June 28, 2018 17:57
Show Gist options
  • Save jcypret/e2a29f040799f429f3ee4059d8967ff3 to your computer and use it in GitHub Desktop.
Save jcypret/e2a29f040799f429f3ee4059d8967ff3 to your computer and use it in GitHub Desktop.
Convert a plain JS object to an encoded query string
export function objectToQueryString(obj) {
return Object.keys(obj)
.map(k => encodeURIComponent(k) + "=" + encodeURIComponent(obj[k] || ""))
.join("&");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment