InterviewHubPRO
Section Overview
Q292

Question 292 of 521

Part 5: ES6+ Modern Syntax, Classes, Modules & Destructuring (254 - 328)

56%
JavaScript Internals (521 Qs)•Part 5: ES6+ Modern Syntax, Classes, Modules & Destructuring (254 - 328)

How to get the value from get parameters

The new URL() object accepts the url string and searchParams property of this object can be used to access the get parameters.

javascript
  let urlString = "http://www.some-domain.com/about.html?x=1&y=2&z=3"; //window.location.href
  let url = new URL(urlString);
  let parameterZ = url.searchParams.get("z");
  console.log(parameterZ); // 3