@damianc/obj-path

1.0.0 • Public • Published

ObjPath

Getting object property by a path string.

const obj = {
  foo: {
  bar: [10, 20, 30, 40]
  }
}

ObjPath(obj, 'foo.bar[1]')
// 20
const obj = {
  foo: {
    bar: [
      120,
      { baz: [{
        quux: 200
      }] }
    ]
  }
};

ObjPath(obj, 'foo.bar[1].baz[0].quux')
// 200
const obj = {
  foo: [1, 2, [3, 4]]
};

ObjPath(obj, 'foo[2][0]')
// 3

Dependencies (0)

    Dev Dependencies (0)

      Package Sidebar

      Install

      npm i @damianc/obj-path

      Weekly Downloads

      3

      Version

      1.0.0

      License

      ISC

      Unpacked Size

      986 B

      Total Files

      3

      Last publish

      Collaborators

      • damianc