Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.javascript > #33971
| From | Joao Rodrigues <groups_jr-1@yahoo.com> |
|---|---|
| Newsgroups | comp.lang.javascript |
| Subject | Re: undefined string in an object? |
| Date | 2017-09-09 11:07 -0300 |
| Organization | Aioe.org NNTP Server |
| Message-ID | <op0sil$dcd$1@gioia.aioe.org> (permalink) |
| References | <bb27e72b-f746-44f9-a1d5-d6c5673b9ef7@googlegroups.com> |
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
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