Object traversal by path
Given a path, e.g. a.b[2].c.d[1].e
, it will navigate down the provided object and return the last value it finds.
You can play with it in a sandbox here
Install
npm install object-traversal-by-path
or
yarn add object-traversal-by-path
Usage
; const object = a: b: c: 'hello world!' ;const path = 'a.b.c'; const value = ; // value === 'hello world!'
This also works with arrays:
; const object = a: b: c: 'hello' c: 'goodbye' ;const path = 'a.b[1].c'; const value = ; // value === 'goodbye'
Mutating
You can deeply mutate objects with the mutate
function.
; const object = a: b: c: 'hello' c: 'goodbye' ;const path = 'a.b[1].c'; const value = ; console; // 'see you soon!'