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.