85. implement `_.get()`

JavaScriptLodash TikTok Amazon

medium  - accepted / - tried

_.get(object, path, [defaultValue]) is a handy method to help retrieving data from an arbitrary object. if the resolved value from path is undefined, defaultValue is returned.

Please create your own get().

const obj = {  a: {    b: {      c: [1,2,3]    }  }}get(obj, 'a.b.c') // [1,2,3]get(obj, 'a.b.c.0') // 1get(obj, 'a.b.c[1]') // 2get(obj, ['a', 'b', 'c', '2']) // 3get(obj, 'a.b.c[3]') // undefinedget(obj, 'a.c', 'bfe') // 'bfe'

Related Lists

lodash

Always try to find a better approach.