Last active
August 29, 2015 14:16
-
-
Save tzmartin/097d17905802aabcb0fe to your computer and use it in GitHub Desktop.
Convert query parameters into JSON objects
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
var str = "myappscheme://foo=bar&hello=world" | |
var queryParamsToJSON = function(str) { | |
var result = {}, name; | |
str = str.split(/:\/\//); | |
str[1].substring(0, str[1].length).split(/\&|=/).forEach(function(item, idx){ | |
idx%2 ? (result[name] = item) : (name = item); | |
}); | |
return result; | |
}; | |
var parsedArgs = queryParamsToJSON(str); | |
console.log(parsedArgs); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment