List Info

Thread: in array




in array
user name
2006-06-13 20:38:19
In that case, x is an object, since { } is syntax sugar for:

var x = new Object();
x.string1 = "stringx";
...

or

x["string1"] = "stringx";

The only advantage of the second over the first is that you
can form
the keys dynamically.

- a

On 6/13/06, Andre <gmandrecgn.de> wrote:
> interesting reading ... so what am I actually doing
when I use this:
>
>         var x = {'string1':'stringx',
'sting2':'stringy'};
>         x['string3'] = 'stringz';
>
> Sorry, for the stupid question ...
> Andre
>
> Aaron Boodman wrote:
> > Is it possible that you are using
> >
> > for (var i in arr) {
> >
> > }
> >
> > ? This is a brittle construction when arr is an
array (as opposed to
> > an object) and should be avoided. See
> > http://ajaxian.com/archives/javascri
pt-associative-arrays-considered-harmful
> >
> >
> > - a
> >
> > On 6/13/06, Nikolas Coukouma <atrusatrus.org> wrote:
> >> Chris Hayes wrote:
> >> > For some reason a script that worked for
a long time now says
> >> >
> >> >  Error: msgdata.content[msg_nr] has no
properties
> >>
> >> It seems weird that it's now an error, but I
can't guess why without
> >> more code.
> >>
> >> > Is there a way to do a check to see
whether msgdata['content'][msg_nr]
> >> > exists / has properties, without causing
an error?
> >> >
> >> > Maybe like the PHP function isset() or
in_array() ?
> >> If something doesn't exist, it's value is
undefined which is considered
> >> false in boolean expressions. So, you can use
it in an if statement:
> >> if(msgdata['content'][msg_nr]) {
> >>   // do stuff
> >> }
> >>
> >> Cheers,
> >> -Nikolas
> >>
> >>
_______________________________________________
> >> Greasemonkey mailing list
> >> Greasemonkeymozdev.org
> >> http:
//mozdev.org/mailman/listinfo/greasemonkey
> >>
>
> _______________________________________________
> Greasemonkey mailing list
> Greasemonkeymozdev.org
> http:
//mozdev.org/mailman/listinfo/greasemonkey
>
_______________________________________________
Greasemonkey mailing list
Greasemonkeymozdev.org
http:
//mozdev.org/mailman/listinfo/greasemonkey
[1]

about | contact  Other archives ( Real Estate discussion Medical topics )