DEV Community

Matt-Howell
Matt-Howell

Posted on • Edited on

How to retrieve GET parameters from JavaScript

window.location.search will return everything from the ? on. This code below will remove the ?, use split to separate into key/value arrays, then assign named properties to the object:

var queryDict = {}
location.search.substr(1).split("&").forEach(function(item) {queryDict[item.split("=")[0]] = item.split("=")[1]})

Read more solutions on How to retrieve GET parameters from JavaScript!

Top comments (0)