How to Find and Retrieve GET Parameters in JavaScript?

Estimated read time 1 min read

To find and retrieve GET parameters in JavaScript, you can use the URLSearchParams object and the window.location.search property.

Here’s an example:

let params = new URLSearchParams(window.location.search);
let id = params.get("id");
console.log(id);

In this example, the code creates a URLSearchParams object using the window.location.search property. The URLSearchParams object provides methods for accessing and manipulating URL query parameters. The code then calls the get method on the params object, passing in the name of the parameter you want to retrieve, in this case "id". The value of the parameter is returned and logged to the console.

You May Also Like

More From Author

+ There are no comments

Add yours

Leave a Reply