Skip to content

Instantly share code, notes, and snippets.

@makotom
Last active December 20, 2015 11:29
Show Gist options
  • Save makotom/6123292 to your computer and use it in GitHub Desktop.
Save makotom/6123292 to your computer and use it in GitHub Desktop.
Another JS implementation to parse query strings
function parseStr(str) {
"use strict";
var ret = {};
str.toString().split("&").forEach(function (term) {
var eqSplit = term.split("="),
fieldName = decodeURIComponent(eqSplit.shift());
if (fieldName === "") {
return;
}
ret[fieldName] = decodeURIComponent(eqSplit.join("="));
});
return ret;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment