How to safely access deeply nested object in Javascript
Issue #390
An object ‘s property can be null or undefined.
Accessing step by step is tedious
1 | props.user && |
Dynamic parsing path is too clever and involves string in the end, which is a no no
1 | const get = (p, o) => |
Instead let’s use function and catch errors explicitly, and defaults with a fallback
1 | const get: (f, defaultValue) => { |