Created
May 18, 2018 21:35
-
-
Save Woodsphreaker/ff5c49f0253ea99792cb9df61654ffb9 to your computer and use it in GitHub Desktop.
get url param
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
const url = 'http://www.xxx.com.br?type=session&value=2&user=15&teste=123' | |
const getParam = (url, param) => { | |
const p = url.indexOf(`${param}=`) | |
const start = url.slice(p + (param.length + 1)) | |
const value = start.slice(0, start.indexOf('&') >>> 0) | |
return (p < 0 || !value) ? false : value | |
} | |
console.log( | |
getParam(url, 'type') | |
, getParam(url, 'value') | |
, getParam(url, 'user') | |
, getParam(url, 'teste') | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment