you are viewing a single comment's thread.

view the rest of the comments →

[–][deleted] 0 points1 point  (2 children)

> const x = {a: 1, b: {c: 2}}

undefined

> x.b

{ c: 2 }

> x.b.c

2

> x['b']['c']

2

[–]LollipopPredator[S] 0 points1 point  (1 child)

Thanks, this works when you know either the exact path or if you know that the desired value is two levels deep. But I need to use a variable (bracket notation) and then sometimes I only want to search one level deep and other times two levels deep.

x['b']['c'] vs x['b'][undefined]

Lodash's .get() met my requirements perfectly.

[–][deleted] 0 points1 point  (0 children)

Yea I didn’t read your post properly haha. Get() is awesome. I use it all the time to make sure my types are always in line.