Created
August 1, 2021 13:03
-
-
Save codetot/d8f7d50575bd9cd67578ddaa9e6ddb56 to your computer and use it in GitHub Desktop.
(Javascript) Remove param from url (standardjs)
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
const removeQueryVar = (key, url) => { | |
let rtn = url.split('?')[0] | |
let param | |
let params = [] | |
let queryString = (url.indexOf('?') !== -1) ? url.split('?')[1] : '' | |
if (queryString !== '') { | |
params = queryString.split('&') | |
for (var i = params.length - 1; i >= 0; i -= 1) { | |
param = params[i].split('=')[0] | |
if (param === key) { | |
params.splice(i, 1) | |
} | |
} | |
if (params.length) rtn = rtn + '?' + params.join('&') | |
} | |
return rtn | |
} | |
// Example use: | |
removeQueryVar('action', currentUrl) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment