Categories
JavaScript Answers

How to remove URL parameters with JavaScript?

Spread the love

Sometimes, we want to remove URL parameters with JavaScript.

In this article, we’ll look at how to remove URL parameters with JavaScript.

How to remove URL parameters with JavaScript?

To remove URL parameters with JavaScript, we use the string replace method.

For instance, we write

const onlyUrl = window.location.href.replace(window.location.search, "");

to call window.location.href.replace to replace the window.location.search query string with an empty string.

Conclusion

To remove URL parameters with JavaScript, we use the string replace 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 *