Programming Tips - javaScript: get querystring (URL) parameter

Date: 2020jan9 Language: javaScript Prose: wrap Q. javaScript: get querystring (URL) parameter A.
function getQsParams() { let params = {}; const pairs = document.location.search.substr(1).split('&'); for (let i = 0; i < pairs.length; i++) { if (pairs[i] == '') continue; const a = pairs[i].split('='); params[a[0]] = a[1]; }; return params; } function exampleUse() { const params = getQsParams(); const userid = params['userid']; console.log('userid=' + userid); }
I looked, jQuery doesn't seem to have a function for this. But this works OK.