<tutorialjinni.com/>

Get Query String Values Using JavaScript

Posted Under: JavaScript, Snippets, Tutorials on Aug 19, 2018
URL Query String was a difficult and time consuming thing before the introduction of URLSearchParams() API, which is supported on all major browsers i.e. Firefox 44+, Opera 36+, Edge 17+, Safari 10.3+ and Chrome 49+. As usual Internet Explorer or Edge still lags behind.
//Sample Url Generation for this example. 
url=new URL('https://www.samplewebsite.com?param1=value1&param2=value2');
urlObject = new URLSearchParams(url.search);
// to get the current URL you can use URLSearchParams(location.search) instead
value=urlObject.get('param2');
console.log(value);
© Tutorial Jinni