Q:

JavaScript URL searchParams not returning anything

I'm trying to run this in the latest version of Chrome (75.0.3770.142), but I'm not getting any search parameters.  For example:
let params = (new URL("http://blah.com?q=something")).searchParams;

This is just returning an empty object, so the query string hasn't been parsed.  I've tried multiple examples but they all return an empty object.  Am I doing something wrong here?

A:

To get all URL parameters, try using searchParams.toString():

var params = (new URL('http://blah.com?q=something')).searchParams.toString();
console.log(params);

To get a specific value by a parameter name, use searchParams.get('q'):

var params = (new URL('http://blah.com?q=something')).searchParams.get('q');
console.log(params);

