Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.javascript > #38390

Re: check for obj nested prop

Path csiph.com!eternal-september.org!feeder.eternal-september.org!reader01.eternal-september.org!james.kirk.invalid!.POSTED!not-for-mail
From James Kirk <noneya.invalid@gmail.com>
Newsgroups comp.lang.javascript
Subject Re: check for obj nested prop
Date Fri, 8 May 2020 11:00:12 -0400
Organization Time Travel Tracing
Lines 42
Message-ID <20200508110012.60d3c6d4@james.kirk.invalid> (permalink)
References <C9udnTlJHfCQbSnDnZ2dnUU7-U3NnZ2d@westnet.com.au>
Reply-To ": James Kirk" <noneya.invalid+knobknocker@gmail.com>
Mime-Version 1.0
Content-Type text/plain; charset=UTF-8
Content-Transfer-Encoding 8bit
Injection-Info james.kirk.invalid; posting-host="8427df9e65a9e77de1de022fabf2995a"; logging-data="18027"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18qrom4GuIQx/g7BX0Dky1ztnVBBxgw7No="
User-Agent Unicorn named Ellie
Cancel-Lock sha1:HazYWaFQfMwHVS3E1zPqVG/W91I=
X-Rot13 This message MAY contains rot13 encoded text that sensitive people may find offense, decode at your own peril.
X-Newsreader Microsoft Windows Dead Mail Original Imitation Prototype
Content-Language en-US
Face iVBORw0KGgoAAAANSUhEUgAAADAAAAAwCAMAAABg3Am1AAAACXBIWXMAAAsTAAALEwEAmpwYAAAAB3RJTUUH4QIHFgQpyK6L9AAAAEJQTFRFAAAAQAAAQEAAQEBAQECAgEBAgECAgIBAgICAgIC/gL+/v4BAv4CAv4C/v7+Av7+/v7//v////7+A/7+///+/////CTpitwAAAAF0Uk5TAEDm2GYAAAABYktHRBXl2PmjAAAB6klEQVRIx61Vi3KEIAz0pJZYUwIi//+r3QT78sTKTDM3N6e3y+5iIsPwT+UcdeHJOSd9Ao6kVyB2CqQkfQKpSI+AS6lDQh2VDoIzR6jYQVCBuymo7tH9EF+OUrwnAfxLFSjp/aajuZTbnujbUYop/dWz7P1kDyFWS4lYLuETyrs5VUKMSTyHthvFe/ZwFD8tRQ68SNvOxFlGh8hFl48oCoF9aOC9l23jB6n5GMHBR1gZfI7nvG2bf0hUL2YLNCWwf3Ilnip+Q2cX86+G8FM9MU/PgcmHDIaMZG6wflGKegLhyZQn4oxCBKlxTaHGBmHxz45ECRkRFFpX1+9UCQdPzHikRtBRiD8rzacEQjbFh5HKjixSzJco/kgQomyM5THvAoKFxXaLzgj40wj2FNSI2NW7pdbM/ritlbBOLu3rm0EnshOO3cHIAEZAIwG949ewvOqFX467ahIIsfJIltN2bF1XngQa/qxhWQkBEUTXzJWAGzCFKeKzaVDGpJllNwR84IlEiM/nIWRG54ERKrwSIDE3Jg57O7ooiVetYIX5o9gca2KcOzAUdnRtbEhcvMKAp/CrriTsoCKM2JenPAwzbr5dKWgYxUr+PoEvCCfq1DyBIf4iPYc8NQ5naUlQeynqJLRf9Z2E4cb58QHWYi4v2VmiigAAAABJRU5ErkJggg==
X-Operating-System Windows 3.0
Xref csiph.com comp.lang.javascript:38390

Show key headers only | View raw


In Message: <C9udnTlJHfCQbSnDnZ2dnUU7-U3NnZ2d@westnet.com.au>
Andrew Poulos <ap_prog@hotmail.com> wrote:

> If I have an object and it get properties added dynamically when I
> need to test for a "nested" property and one of the "ascendant"
> properties doesn't exist I get an error. For example,

> let obj = {a: 1};
> if (a.b.c.d) // throws error

> so I end up doing

> if (a && a.b && a.b.c && a.b.c.d)

> What happens is that every now and then I get caught when I assume
> the properties should exist.

> 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?

nested destructuring

let objA = {big: 'toe'},
objB = {A: {B: {C: {D: 'look at D' } } } },
{a,a:{b,b:{c,c:{d}=''}=''}=''} = objA,
{A,A:{B,B:{C,C:{D}=''}=''}=''} = objB;

console.log(a);
console.log(b);
console.log(c);
console.log(d);

console.log(A);
console.log(B);
console.log(C);
console.log(D);

-- 
James Kirk

Back to comp.lang.javascript | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

check for obj nested prop Andrew Poulos <ap_prog@hotmail.com> - 2020-05-08 15:37 +1000
  Re: check for obj nested prop Ben Bacarisse <ben.usenet@bsb.me.uk> - 2020-05-08 10:52 +0100
    Re: check for obj nested prop Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2020-05-09 00:26 +0200
      Re: check for obj nested prop Ben Bacarisse <ben.usenet@bsb.me.uk> - 2020-05-09 03:09 +0100
        Re: check for obj nested prop Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2020-05-12 09:28 +0200
          Re: check for obj nested prop Julio Di Egidio <julio@diegidio.name> - 2020-05-12 04:01 -0700
    Exception handling (was: check for obj nested prop) Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2020-05-09 03:46 +0200
  Re: check for obj nested prop JJ <jj4public@vfemail.net> - 2020-05-08 17:18 +0700
  Re: check for obj nested prop Julio Di Egidio <julio@diegidio.name> - 2020-05-08 03:53 -0700
  Re: check for obj nested prop James Kirk <noneya.invalid@gmail.com> - 2020-05-08 11:00 -0400
  Re: check for obj nested prop Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2020-05-09 00:19 +0200
    Re: check for obj nested prop Julio Di Egidio <julio@diegidio.name> - 2020-05-12 04:04 -0700
      Re: check for obj nested prop luserdroog <luser.droog@gmail.com> - 2020-05-12 07:59 -0700
  Re: check for obj nested prop "Michael Haufe (TNO)" <tno@thenewobjective.com> - 2020-05-12 14:17 -0700
    Re: check for obj nested prop Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2020-05-13 02:46 +0200
    Re: check for obj nested prop Andrew Poulos <ap_prog@hotmail.com> - 2020-05-13 13:08 +1000
      Re: check for obj nested prop "Michael Haufe (TNO)" <tno@thenewobjective.com> - 2020-05-13 12:30 -0700

csiph-web