Bring Ruby's Hash#dig method to JavaScript/Node.
You can install this package via npm
.
npm install --save @drm2/dig.js
You can use this library as a method of Object
to make things more natural, or you can just use it as a standalone function
.
require('@drm2/dig.js').init();
var test = { hello: { world: '!' } };
test.dig('hello', 'world'); // returns '!'
test.dig('fake', 'props'); // returns null
var dig = require('@drm2/dig.js').dig;
var test = { hello: { world: '!' } };
dig(test, 'hello', 'world'); // returns '!'
dig(test, 'fake', 'props'); // returns null