Categories
JavaScript Answers

How to get JavaScript window.location.href without the hash?

Spread the love

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.

Leave a Reply

Your email address will not be published.

If you like the content of this blog, subscribe to my email list to get exclusive articles not available to anyone else.