Skip to content

Instantly share code, notes, and snippets.

@Woodsphreaker
Created May 18, 2018 21:35
Show Gist options
  • Save Woodsphreaker/ff5c49f0253ea99792cb9df61654ffb9 to your computer and use it in GitHub Desktop.
Save Woodsphreaker/ff5c49f0253ea99792cb9df61654ffb9 to your computer and use it in GitHub Desktop.
get url param
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