Skip to content

Instantly share code, notes, and snippets.

@hoyangtsai
Created January 20, 2022 17:54
Show Gist options
  • Save hoyangtsai/2323e7932d295b53b023cdbb781cc27e to your computer and use it in GitHub Desktop.
Save hoyangtsai/2323e7932d295b53b023cdbb781cc27e to your computer and use it in GitHub Desktop.
object to url query string #snippet
// convert objec to a query string
const qs = Object.keys(params)
.map(key => `${key}=${params[key]}`)
.join('&');
// OR
var queryString = Object.keys(params).map((key) => {
return encodeURIComponent(key) + '=' + encodeURIComponent(params[key])
}).join('&');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment