Created
March 26, 2021 11:31
-
-
Save yavgel85/d1d36bede5c04af367c38f4cdfa33d4c to your computer and use it in GitHub Desktop.
getBaseURL #js #browser
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
// Gets the current URL without any parameters or fragment identifiers. | |
// Use String.prototype.replace() with an appropriate regular expression to remove everything after either '?' or '#', if found. | |
const getBaseURL = url => url.replace(/[?#].*$/, ''); | |
// Examples | |
getBaseURL('http://url.com/page?name=Adam&surname=Smith'); // 'http://url.com/page' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment