Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
How to get all parameters from a URL as an associative array
export const getURLparams = () => {
const pl = /\+/g;
const search = /([^&=]+)=?([^&]*)/g;
const decode = s => decodeURIComponent(s.replace(pl, ' '));
const query =;
const urlParams = {};
let match;
while ((match = search.exec(query))) {
urlParams[decode(match[1])] = decode(match[2]);
return urlParams;

This comment has been minimized.

Copy link
Owner Author

@magician11 magician11 commented Jul 1, 2018

Code inspired from


if the URL is

const params = getURLparams();

this would output

Object {bob: "john", id: "123"}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.