Path: csiph.com!eternal-september.org!feeder.eternal-september.org!reader01.eternal-september.org!.POSTED!not-for-mail From: Ben Bacarisse Newsgroups: comp.lang.javascript Subject: Re: check for obj nested prop Date: Fri, 08 May 2020 10:52:29 +0100 Organization: A noiseless patient Spider Lines: 20 Message-ID: <87pnbeycrm.fsf@bsb.me.uk> References: Mime-Version: 1.0 Content-Type: text/plain Injection-Info: reader02.eternal-september.org; posting-host="b3a165f82640ad14e1ffceba35650cd1"; logging-data="16646"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18HLlRlRGEg1jqee7L/8cP8f0OxB/6N1CU=" Cancel-Lock: sha1:/8gg7fBvlBoNW2P6ILCigIiWS88= sha1:eYtwNuGtqw/FmIu6LkRZz89K3E8= X-BSB-Auth: 1.e4c2bc8423b38bc0c273.20200508105229BST.87pnbeycrm.fsf@bsb.me.uk Xref: csiph.com comp.lang.javascript:38387 Andrew Poulos writes: > let obj = {a: 1}; > if (a.b.c.d) // throws error Did you mean if (obj.a.b.c.d) ? > so I end up doing > > if (a && a.b && a.b.c && a.b.c.d) > Is there a way to get the check value of an object's nested property > without first having to test for all the ascendant properties? if (try {obj.a.b.c.d} catch {}) might do what you want. -- Ben.