0 points

How to get URL Parameters?


dashboard

Wed Apr 29 2020 10:59:32 GMT+0000 (UTC)

Posted by @Doll #javascript

const getURLParameters = url =>
  (url.match(/([^?=&]+)(=([^&]*))/g) || []).reduce(
    (a, v) => ((a[v.slice(0, v.indexOf('='))] = v.slice(v.indexOf('=') + 1)), a),
    {}
  );
EXAMPLES
getURLParameters('http://url.com/page?name=Adam&surname=Smith'); // {name: 'Adam', surname: 'Smith'}
getURLParameters('google.com'); // {}                                
                                
content_copy Copy

The above code is used to get URL parameters.

https://www.30secondsofcode.org/js/s/get-url-parameters/