Last active
December 21, 2015 23:08
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
postParameterNameComponents("postdata[with][dimensions]") | |
-> ["postdata", "with", "dimensions"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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