omninews / findByPath

Find nested properties in an object by specifying a path, eg "level1.level2.0.name"

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

findByPath

Find nested properties in an object by specifying a path, eg "level1.level2.0.name".

var findByPath = require('findByPath'),
obj = {
  level1: true,
  parent: {
    level2: "true"
  }
};

findByPath(obj, 'level1'); // true
findByPath(obj, 'parent.level2'); // "true"
findByPath(obj, 'parent/level2', '/'); // "true"
findByPath(obj, 'parent.child'); // undefined

See tests for more examples.

Contributors

Rodney Rehm contributed the better part of the code to Reol.js. Thanks!

About

Find nested properties in an object by specifying a path, eg "level1.level2.0.name"


Languages

Language:JavaScript 100.0%