1-liners
Version:
Useful oneliners and shorthand functions
17 lines (16 loc) • 316 B
JavaScript
/**
* @module 1-liners/get
*
* @description
*
* Gets the value at path of object.
*
* @example
*
* const get = require('1-liners/get');
*
* let obj = { a: { b: 42 } };
* get('a.b', obj); // => 42
*
*/
export default (path, obj) => path.split('.').reduce((acc, current) => acc && acc[current], obj);