Advertisement
728x90
The new URL() object accepts the url string and searchParams property of this object can be used to access the get parameters.
javascript
1let urlString = "http://www.some-domain.com/about.html?x=1&y=2&z=3"; //window.location.href
2
3let url = new URL(urlString);
4
5let parameterZ = url.searchParams.get("z");
6
7console.log(parameterZ); // 3Advertisement
Responsive Ad
🎯 Practice NowRelated Challenge
JavaScript Coding Exercise 32
Test your knowledge with this interactive coding challenge.
Start CodingAdvertisement
728x90
288of476