String.prototype.replace()
with an appropriate regular expression to remove everything after either '?'
or '#'
, if found.const getBaseURL = url => url.replace(/[?#].*$/, '');
getBaseURL('http://url.com/page?name=Adam&surname=Smith');
// 'http://url.com/page'
Subscribe to get resources directly to your inbox. You won't receive any spam! ✌️