How to Remove a Query String From a URL in JavaScript

 

How do I remove a specific query string from a URL?

 

const url = 'http://localhost/console/addproduct.php?page=5&sort=desc'; 
const urlObj = new URL(url); 
		urlObj.search = ''; 
const result = urlObj.toString(); console.log(result);

Tags:

Share:

Related posts