Path: csiph.com!aioe.org!.POSTED!not-for-mail From: Joao Rodrigues 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: References: 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 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. 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 -- Joao Rodrigues