Skip to content

Instantly share code, notes, and snippets.

@NaClYen
Last active October 21, 2021 09:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save NaClYen/de4036bff89eddd644fb0d6094bb6df9 to your computer and use it in GitHub Desktop.
Save NaClYen/de4036bff89eddd644fb0d6094bb6df9 to your computer and use it in GitHub Desktop.
JS - url search params to dictionary
let dict = Array.from(new URLSearchParams(window.location.search)).reduce(
(d, [k, v]) => {
d[k] = v;
return d;
},
{}
);
const a = new URLSearchParams(window.location.search);
const b = Array.from(a);
const c = b.reduce((dict, [key, value]) => {
dict[key] = value;
return dict;
}, {});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment