|
|
|
|
|
by mbell
2931 days ago
|
|
> Sure, things like map, filter, find, reduce, etc... are made obsolete Not really. `_.map` for example works on Objects, and property access is very nice. `_.map(object, 'myProperty.mySubProperty')` vs `Object.values(object).map(i => i.myProperty ? i.myProperty.mySubProperty : undefined)` |
|
Although that being said, for deep property access like you have, i still reach for lodash's `get`, or more recently i'm beginning to use the new stage-1 proposal for "optional chaining" (also known as null-conditional operator in C#) [0].
That turns your second example into:
And honestly I might even reach for destructuring depending on the use case: As nice as lodash's syntax is, it can be confusing for those who don't know it, and even I need to step back sometimes when I see it used heavily somewhere and almost replay what is happening in my head.[0] https://github.com/tc39/proposal-optional-chaining