Sometimes, we want to get JavaScript window.location.href without the hash.
In this article, we’ll look at how to get JavaScript window.location.href without the hash.
How to get JavaScript window.location.href without the hash?
To get JavaScript window.location.href without the hash, we can use the string split method.
For instance, we write
const [uri] = window.location.href.split("#");
to call window.location.href.split withh '#' and destructure the first part to get the URL without the hash part and assign it to uri.
Conclusion
To get JavaScript window.location.href without the hash, we can use the string split method.