[Greasemonkey] Re: in array

Andre gm at andrecgn.de
Tue Jun 13 14:44:24 EDT 2006


thanks :-)
Andre

Aaron Boodman wrote:
> 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 <gm at andrecgn.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/javascript-associative-arrays-considered-harmful 
>>
>> >
>> >
>> > - a
>> >
>> > On 6/13/06, Nikolas Coukouma <atrus at atrus.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
>> >> Greasemonkey at mozdev.org
>> >> http://mozdev.org/mailman/listinfo/greasemonkey
>> >>
>>
>> _______________________________________________
>> Greasemonkey mailing list
>> Greasemonkey at mozdev.org
>> http://mozdev.org/mailman/listinfo/greasemonkey
>>



More information about the Greasemonkey mailing list