UNPKG

@e-group/utils

Version:

eGroup team utils that share across projects.

24 lines (19 loc) 579 B
/** * To solve index path bug please read this for more detail. * https://stackoverflow.com/questions/6393943/convert-javascript-string-in-dot-notation-into-an-object-reference */ const findDeepValue = (obj, path = '') => { var _path$match; const matchArray = (_path$match = path.match(/[^\]\\[.]+/g)) !== null && _path$match !== void 0 ? _path$match : []; const result = matchArray.reduce((o, i) => { if (o) { return o[i]; } return undefined; }, obj); if (!result) { return undefined; } return result; }; export default findDeepValue;