[Greasemonkey] Re: in array

Nikolas Coukouma atrus at atrus.org
Tue Jun 13 16:43:24 EDT 2006


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



More information about the Greasemonkey mailing list