How to Get URL Parameters with JavaScript

we can grab the query string using window.location.search

const queryString = window.location.search;

We can then parse the query string’s parameters using URLSearchParams

const urlParams = new URLSearchParams(queryString);

URLSearchParams.get() will return the first value associated with the given search parameter

const product = urlParams.get('product')

Leave a comment

Your email address will not be published. Required fields are marked *