Skip to content

Instantly share code, notes, and snippets.

@aradnom
Created September 28, 2015 19:37
Show Gist options
  • Save aradnom/734a06445b19f7d554b1 to your computer and use it in GitHub Desktop.
Save aradnom/734a06445b19f7d554b1 to your computer and use it in GitHub Desktop.
Explode array component string into usable array of properties, i.e. 'field[subfield1][subfield2][subfield3]' => ["field", "subfield1", "subfield2", "subfield3"]
/**
* Explode array component string into usable array of properties, i.e.
* 'field[subfield1][subfield2][subfield3]' =>
* ["field", "subfield1", "subfield2", "subfield3"]
*
* @param {String} string String of fields
*
* @return {Array} Returns array of field properties
*/
function arrayStringToProperties ( string ) {
return string
.split( ']' )
.join( '' )
.split( '[' )
.filter( function ( v ) {
return v;
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment