Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.javascript > #36889
| Newsgroups | comp.lang.javascript |
|---|---|
| Subject | Re: Object prop missing? |
| From | "Evertjan." <exxjxw.hannivoort@inter.nl.net> |
| References | <p6KdnbVLAPPqcZzAnZ2dnUU7-QfNnZ2d@westnet.com.au> <12600445.cR47uQ6sgG@PointedEars.de> <kcidnW32l-lhgp_AnZ2dnUU7-TvNnZ2d@westnet.com.au> |
| Date | 2019-06-13 12:33 +0200 |
| Message-ID | <XnsAA6D7FBCFA34eejj99@194.109.6.166> (permalink) |
Andrew Poulos <ap_prog@hotmail.com> wrote on 13 Jun 2019 in
comp.lang.javascript:
> On 13/06/2019 5:36 pm, Thomas 'PointedEars' Lahn wrote:
>> Andrew Poulos wrote:
>>
>>> I've created a property and the console it tells me that it looks like
>>> this
>>>
>>> Object
>>> elem: div#opt1.opt
>>> h: 28
>>> id: "opt1"
>>> maxw: 548
>>> on: false
>>> pos: {x: 46}
>>> txt: p
>>> __proto__: Object
>>>
>>> yet when, right after, I try to get the value of op.h I get undefined
>>>
>>> console.log(op) //--> give the object above
>>> console.log(op.h) //--> undefined
>>>
>>> I don't understand how this could be happening.
>>
>> Show the code used to create and query the object, i.e. the entire
>> relevant part of the console transcript, *verbatim*. And name the
>> runtime environment so that one can take at least a guess at the used
>> ECMAScript implementation.
>
> var options = [
> {},
> {"id": "opt1", "on": false },
> {"id": "opt2", "on": false },
> {"id": "opt3", "on": false },
> {"id": "opt4", "on": false },
> {"id": "opt5", "on": false }
> ];
>
> for (var i = 6; i > 0; i--) {
> // add stuff to options elements
> options[i].h = 28;
>}
>
> showOptions();
>
> function showOptions() {
> console.log(options[1]); // 1.
> console.log(options[1].h) // 2.
> console.log(typeof options[1]); // 3.
>
> // code that relies on .h values
>}
>
> In Windows Chrome 75.0.3770.80 (64-bit):
>
> 1.
> > Object
>
> when opened
>
> v Object
> > elem: div#opt1.opt
> h: 28
> id: "opt1"
> maxw: 548
> on: false
> > pos: {x: 46}
> > txt: p
> __proto__: Object
>
> 2. undefined
>
> 3. object
>
> h is in options[1] but when I try to get the value it's not.
>
> Andrew Poulos
You did not test this, because option[6] does not exist and gives an error.
However this works fine:
var options = [
{},
{"id": "opt1", "on": false },
{"id": "opt2", "on": false },
{"id": "opt3", "on": false },
{"id": "opt4", "on": false },
{"id": "opt5", "on": false }
];
options[1].h = 28;
showOptions();
function showOptions() {
console.log(options[1]);
console.log(options[1].h);
console.log(typeof options[1]);
}
// {id: "opt1", on: false, h: 28}
// 28
// object
--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Back to comp.lang.javascript | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Object prop missing? Andrew Poulos <ap_prog@hotmail.com> - 2019-06-13 16:25 +1000
Re: Object prop missing? Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2019-06-13 09:37 +0200
Re: Object prop missing? Andrew Poulos <ap_prog@hotmail.com> - 2019-06-13 20:05 +1000
Re: Object prop missing? "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2019-06-13 12:33 +0200
Re: Object prop missing? Andrew Poulos <ap_prog@hotmail.com> - 2019-06-13 20:53 +1000
Re: Object prop missing? Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2019-06-13 13:09 +0200
Re: Object prop missing? Andrew Poulos <ap_prog@hotmail.com> - 2019-06-13 21:54 +1000
Re: Object prop missing? Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2019-06-13 17:30 +0200
Re: Object prop missing? Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2019-06-13 13:05 +0200
Re: Object prop missing? JJ <jj4public@vfemail.net> - 2019-06-13 15:41 +0700
csiph-web