dynamic-forms / Function

splitPath

Splits a path into segments, supporting both dot notation and bracket notation.

Handles:

  • Dot notation: parent.child.grandchild
  • Bracket notation: items[0].quantity
  • Mixed notation: items[0].address.city

Presentation

function splitPath(path: string): string[];

Returns

string[] -

Array of path segments

Parameters

NameTypeDescription
path
string

The path to split

Example usage

splitPath('parent.child.grandchild')
// ['parent', 'child', 'grandchild']

splitPath('items.0.quantity')
// ['items', '0', 'quantity']

splitPath('items[0].quantity')
// ['items', '0', 'quantity']

splitPath('a[0][1].b')
// ['a', '0', '1', 'b']