In my JavaScript, I'm using an object as an associative array. It always has the property "main", and may have others. So, when I create it I might do this:
var myobject = new Object ();
myobject["main"] = somevalue;
Other properties may be added later. Now, at some moment I need to know whether myobject has just the one property, or several, and take different actions depending (I'm only referring to properties I've created).
So far all I've found to do is something like:
flag = false;
for (i in myobject)
{
if (i=="main") continue;
flag = true;
break;
}
and then branch on flag. Or:
for (i in myobject)
{
if (i=="main") continue;
do_some_actions ();
break;
}
These approaches work but feel to me like I've overlooked something. Is there a better approach?