views:

151

answers:

1

Is there a function that allows me to determine the number of keys in an ActionScript 2 associative array without iterating over that array?

// ascertain the length/size of an associative array
var o:Object = new Object();
o["k1"] = "v1";
o["k2"] = "v2";
o["k3"] = "v3";

I'd expect there to be an "o.size" or "o.length" that would return 3.

Thanks.

A: 
var o:Object = new Object();
o["k1"] = "v1";
o["k2"] = "v2";
o["k3"] = "v3";

var len:Number = 0;
for( i in o ) len++;
trace( len );

Sorry, there's no length/size for an Object, iteration is your only choice. AS3 has better options for this with the Dictionary class.

pixelbreaker
Thanks for taking the time to answer.
jsinnott