Skip to content

Instantly share code, notes, and snippets.

@MiguelCastillo
Last active March 22, 2016 22:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MiguelCastillo/23fe49f7287f6983ad8d to your computer and use it in GitHub Desktop.
Save MiguelCastillo/23fe49f7287f6983ad8d to your computer and use it in GitHub Desktop.
function keypath(input) {
var regex = /(\w+)|\[([^\]]+)\]/g;
var result = [];
var path;
while ((path = regex.exec(input || ''))) {
if (input[path.index] === '[') {
result.push(path[2]);
}
else {
result.push(path[1]);
}
}
return result;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment