Created
April 30, 2018 19:00
-
-
Save pankajladhar/5fc8a66bbbd615a3d4da5a50b1a0ef71 to your computer and use it in GitHub Desktop.
Encode an object into query string
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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