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.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *