Proposal: Object.path([ ... ], defaultValue)

Vikash Agrawal vikashagrawal1990 at gmail.com
Thu Feb 15 22:34:27 UTC 2018


Sure Sebastian.

On Fri, 16 Feb 2018 at 3:59 AM, Sebastian Malton <sebastian at malton.name>
wrote:

> This would be redundant because of the `?.` operator once it gets merged
>
> Sebastian Malton
> *From:* vikashagrawal1990 at gmail.com
> *Sent:* February 15, 2018 5:27 PM
> *To:* es-discuss at mozilla.org
> *Subject:* Proposal: Object.path([ ... ], defaultValue)
>
> Hello Everyone,
>
> It is a lot of times that we see `x is not a property of undefined` and to
> solve this we have to resort to &&, something like -> data &&
> data.childData && data.childData.innerDataArray &&
> data.childData.innerDataArray.length > 0 whiich is quiet verbose.
>
> I suggest, we should add a utility method like Object.path, which takes
> an array of strings and returns the value from a given nested object. Also,
> this can take a second argument which will be a default value if not found.
>
> This is inspired by path and pathOr as implemented in
> http://ramdajs.com/docs/#path
>
> Regards
> ~Vikash
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20180215/e18214a6/attachment.html>


More information about the es-discuss mailing list