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


Groups > comp.lang.javascript > #33971

Re: undefined string in an object?

Path csiph.com!aioe.org!.POSTED!not-for-mail
From Joao Rodrigues <groups_jr-1@yahoo.com>
Newsgroups comp.lang.javascript
Subject Re: undefined string in an object?
Date Sat, 9 Sep 2017 11:07:18 -0300
Organization Aioe.org NNTP Server
Lines 35
Message-ID <op0sil$dcd$1@gioia.aioe.org> (permalink)
References <bb27e72b-f746-44f9-a1d5-d6c5673b9ef7@googlegroups.com>
NNTP-Posting-Host HNgRgWocF59EPhAvfrr0+Q.user.gioia.aioe.org
Mime-Version 1.0
Content-Type text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding 7bit
X-Complaints-To abuse@aioe.org
User-Agent Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.3.0
X-Notice Filtered by postfilter v. 0.8.2
Content-Language en-US
Xref csiph.com comp.lang.javascript:33971

Show key headers only | View raw


JRough wrote:
> me (JRough change)
> 
> 4:31 PM (less than a minute ago)
> 
> 
> var a={}; a["b"]=123, a["c"]=456; console.log(a["b"]); undefined
> 
> var a={}; a.b=123, a.c=456; console.log(a.b); undefined
> 
> 
> Why is this object literal not defined?  If it is because it was
> stringified how to make it an object again so you get the value?
> tnx,
> 

This object literal is being defined accordingly.
var a = {};
a["b"]=123, a["c"]=456;
          ^^^

There you have used the comma operator, maybe unwittingly, but it was ok 
in this case.
<https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Comma_Operator>

console.log(a["b"]) is returning "123", and then undefined.

If you write console.log(a) or console.dir(a), you'll retrieve:
{ b: 123, c: 456 }

See also 
<https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Property_Accessors>

-- 
Joao Rodrigues

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


Thread

undefined string in an object? JRough <janis.rough@gmail.com> - 2017-09-06 16:33 -0700
  Re: undefined string in an object? Joao Rodrigues <groups_jr-1@yahoo.com> - 2017-09-09 11:07 -0300
    Re: undefined string in an object? Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2017-09-10 16:20 +0200
      Re: undefined string in an object? John G Harris <niam@jghnorth.org.uk.invalid> - 2017-09-18 15:37 +0100
        Re: undefined string in an object? Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2017-09-18 17:17 +0200
          Re: undefined string in an object? John G Harris <niam@jghnorth.org.uk.invalid> - 2017-09-19 11:05 +0100
            Re: undefined string in an object? Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2017-09-19 12:58 +0200
              Re: undefined string in an object? Flng Fck <nothanks@invalid.invalid> - 2017-09-20 09:37 +0200
              Re: undefined string in an object? John G Harris <niam@jghnorth.org.uk.invalid> - 2017-09-20 10:49 +0100
                Re: undefined string in an object? Ben Bacarisse <ben.usenet@bsb.me.uk> - 2017-09-20 20:29 +0100
                Re: undefined string in an object? John G Harris <niam@jghnorth.org.uk.invalid> - 2017-09-21 16:12 +0100
  Re: undefined string in an object? jonas.thornvall@gmail.com - 2017-09-22 06:11 -0700
    Re: undefined string in an object? "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2017-09-22 19:20 +0200
    Re: undefined string in an object? John G Harris <niam@jghnorth.org.uk.invalid> - 2017-09-23 10:55 +0100
      Re: undefined string in an object? jonas.thornvall@gmail.com - 2017-09-23 09:02 -0700

csiph-web