Last active
March 22, 2016 22:25
-
-
Save MiguelCastillo/23fe49f7287f6983ad8d to your computer and use it in GitHub Desktop.
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 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