I have a string like this:
abc=foo&def=%5Basf%5D&xyz=5
How can I convert it into a JavaScript object like this?
{
A concise solution:
location.search .slice(1) .split('&') .map(p => p.split('=')) .reduce((obj, pair) => { const [key, value] = pair.map(decodeURIComponent); obj[key] = value; return obj; }, {});