Skip to content

Instantly share code, notes, and snippets.

@stefanlindbohm
Last active December 21, 2015 23:08
Show Gist options
  • Save stefanlindbohm/6379667 to your computer and use it in GitHub Desktop.
Save stefanlindbohm/6379667 to your computer and use it in GitHub Desktop.
Get components from POST data names in Javascript, similar to how Rails among others parses params.
postParameterNameComponents("postdata[with][dimensions]")
-> ["postdata", "with", "dimensions"]
function postParameterNameComponents(name) {
var components = [];
var regex = /\[([^\[\s]*)\]/g;
components.push(name.split(regex, 1)[0]);
var match;
while ((match = regex.exec(name)) !== null) {
components.push(match[1]);
}
return components;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment