How to convert URL parameters to a JavaScript object? [duplicate]
In the year 2021… Please consider this obsolete. Edit This edit improves and explains the answer based on the comments. var search = location.search.substring(1); JSON.parse(‘{“‘ + decodeURI(search).replace(/”/g, ‘\\”‘).replace(/&/g, ‘”,”‘).replace(/=/g,'”:”‘) + ‘”}’) Example Parse abc=foo&def=%5Basf%5D&xyz=5 in five steps: decodeURI: abc=foo&def=[asf]&xyz=5 Escape quotes: same, as there are no quotes Replace &: abc=foo”,”def=[asf]”,”xyz=5 Replace =: abc”:”foo”,”def”:”[asf]”,”xyz”:”5 Suround with … Read more