Final answer:
You can use the window.location.search property and URLSearchParams constructor to get query parameters from a URL in JavaScript.
Step-by-step explanation:
To get query parameters from a URL in JavaScript, you can use the window.location.search property. This property returns the query string part of the URL, including the question mark. To extract the query parameters, you can use the URLSearchParams constructor and its various methods. Here's an example:
const urlParams = new URLSearchParams(window.location.search);
const param1 = urlParams.get('param1');
const param2 = urlParams.get('param2');
console.log(param1); // Outputs the value of 'param1'
console.log(param2); // Outputs the value of 'param2'