Parses a keypath string into an array of individual keys, supporting dot and bracket notation.
Parsing rules:
.
'foo.bar'
['foo', 'bar']
[]
'foo["bar-baz"]'
['foo', 'bar-baz']
'foo[0]'
'foo.bar[0].baz'
['foo', 'bar', 0, 'baz']
Limitations:
The keypath string to parse, using dot and/or bracket notation.
An array of keys, where each key is a string or number. Bracketed integer keys are returned as numbers; all others as strings.
parseKeypath('foo.bar'); // ['foo', 'bar']parseKeypath('foo[0].baz'); // ['foo', 0, 'baz']parseKeypath('foo["bar-baz"].quux'); // ['foo', 'bar-baz', 'quux']parseKeypath("foo['bar-baz'].quux"); // ['foo', 'bar-baz', 'quux']parseKeypath("arr[10]['spam']"); // ['arr', 10, 'spam'] Copy
parseKeypath('foo.bar'); // ['foo', 'bar']parseKeypath('foo[0].baz'); // ['foo', 0, 'baz']parseKeypath('foo["bar-baz"].quux'); // ['foo', 'bar-baz', 'quux']parseKeypath("foo['bar-baz'].quux"); // ['foo', 'bar-baz', 'quux']parseKeypath("arr[10]['spam']"); // ['arr', 10, 'spam']
Parses a keypath string into an array of individual keys, supporting dot and bracket notation.
Parsing rules:
.(e.g.,'foo.bar'→['foo', 'bar']).[]. If the key is a quoted string (single or double quotes), the quotes are removed (e.g.,'foo["bar-baz"]'→['foo', 'bar-baz']). If the key is an integer (e.g.,'foo[0]'), it is parsed as a number.'foo.bar[0].baz'→['foo', 'bar', 0, 'baz']).Limitations: