---
title: "How to remove URL encoding in my querystring using Javascript?"  
description: "How to remove URL encoding in my querystring using Javascript?"  
author: "Steilla Mitchel"  
published: 2023-07-21  
updated: 2023-07-21  
canonical: https://www.mindstick.com/forum/159203/how-to-remove-url-encoding-in-my-querystring-using-javascript  
category: "javascript"  
tags: ["javascript", "url rewriting", "url"]  
reading_time: 2 minutes  

---

# How to remove URL encoding in my querystring using Javascript?

How to [remove](https://yourviews.mindstick.com/story/4554/8-harmful-weeds-to-remove-from-garden) [URL](https://www.mindstick.com/forum/436/url-redirection) [encoding](https://www.mindstick.com/interview/752/how-is-encoding-handled-in-ajax) in my [querystring](https://www.mindstick.com/interview/123/what-is-querystring-benefits-and-limitations-of-using-querystring) using [Javascript](https://www.mindstick.com/articles/874/how-to-create-watermark-text-for-textbox-by-using-javascript)?

## Replies

### Reply by Aryan Kumar

Sure, here is how you can remove URL encoding in your querystring using JavaScript:

JavaScript

```plaintext
function removeUrlEncoding(querystring) {
  // Create a new URL object from the querystring.
  const url = new URL(querystring);

  // Get the query parameters from the URL object.
  const queryParams = url.searchParams;

  // Create a new empty string.
  let decodedQueryString = "";

  // Iterate over the query parameters.
  for (const [key, value] of queryParams) {
    // Decode the key and value.
    key = decodeURIComponent(key);
    value = decodeURIComponent(value);

    // Append the key and value to the decodedQueryString string.
    decodedQueryString += `${key}=${value}&`;
  }

  // Remove the trailing "&" character from the decodedQueryString string.
  decodedQueryString = decodedQueryString.slice(0, -1);

  // Return the decodedQueryString string.
  return decodedQueryString;
}

// Test the function.
const querystring = "foo=bar&baz=qux";
const decodedQueryString = removeUrlEncoding(querystring);
console.log(decodedQueryString); // foo=bar&baz=qux
```

This function first creates a new URL object from the querystring. It then gets the query parameters from the URL object. Next, it creates a new empty string. Finally, it iterates over the query parameters, decoding the key and value for each parameter. It then appends the key and value to the decodedQueryString string. The trailing "&" character is removed from the decodedQueryString string before it is returned.

To use this function, you would first need to create a JavaScript variable to store the querystring that you want to decode. You would then call the `removeUrlEncoding()` function, passing the querystring variable as an argument. The function would then return the decoded querystring string.


---

Original Source: https://www.mindstick.com/forum/159203/how-to-remove-url-encoding-in-my-querystring-using-javascript

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
