Created
January 19, 2017 08:46
-
-
Save xiekw2010/7d36ed5a46063e2c69b9c45ab230bdf3 to your computer and use it in GitHub Desktop.
object to query string
This file contains 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
function object2QueryString(obj) { | |
let queryString = '' | |
if (Object.keys(obj).length) { | |
queryString = Object | |
.keys(obj) | |
.map(k => k + '=' + obj[k]) | |
.reduce((a, b) => a + '&' + b, '') | |
} | |
return queryString.slice(1) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment