Shouldn't it be:
_.get(obj, "user.pets[0].toys[0].price");
Instead of:
_.get(obj, 'obj.user.pets[0].toys[0].price');
?
Plus, you don't want to import the whole 69kb of Lodash just for this matter. Since you are using ECMAScript Modules, you should use named imports instead.
import { get } from "lodash"; const obj = { user: { name: "Joe", age: 20, pets: [ { name: "Daffodil", type: "dog", toys: [ { name: "Toughy", price: 1999 } ] } ] } }; console.log(get(obj, "user.pets[0].toys[0].price")); // 1999
Niftier, and does not import the unnecessary functions just to use the get helper.
get
Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink.
Hide child comments as well
Confirm
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Shouldn't it be:
Instead of:
?
Plus, you don't want to import the whole 69kb of Lodash just for this matter. Since you are using ECMAScript Modules, you should use named imports instead.
Niftier, and does not import the unnecessary functions just to use the
get
helper.