Skip to content

Instantly share code, notes, and snippets.

@pankajladhar
Created April 30, 2018 19:00
Show Gist options
  • Save pankajladhar/5fc8a66bbbd615a3d4da5a50b1a0ef71 to your computer and use it in GitHub Desktop.
Save pankajladhar/5fc8a66bbbd615a3d4da5a50b1a0ef71 to your computer and use it in GitHub Desktop.
Encode an object into query string
const params = {id: '1', name: 'foo', isAcive: false};
const query = '?' + Object.keys(params)
.map(param =>
encodeURIComponent(param) + '=' + encodeURIComponent(params[param])
)
.join('&');
console.log (query) // ?id=1&name=foo&isAcive=false
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment