Created
May 31, 2017 10:52
-
-
Save dashedstripes/fcf19367b4feeecca1399aa68b3db7ad to your computer and use it in GitHub Desktop.
Create an object from query params on a url
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
/** | |
* Returns the query params of a url | |
* @param {string} url - the url to process | |
* @return {object} a key value object of the params | |
*/ | |
function getURLParams(url) { | |
let params = {}; | |
let rawParams = ''; | |
if(url.split('?')[1] != undefined) { | |
rawParams = url.replace('%20', ' ').split('?')[1]; | |
} | |
if(rawParams != '') { | |
let paramsArray = rawParams.split('&'); | |
paramsArray.forEach((val, index) => { | |
let item = val.split('='); | |
params[item[0]] = item[1] | |
}) | |
} | |
return params | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment