Search code examples
actionscript-3apache-flexflex3

Calculating Dictionary length in Flex


What's the best way to calculate the length of a Dictionary object in Flex?

var d:Dictionary = new Dictionary();
d["a"] = "alpha";
d["b"] = "beta";

I want to check the length which should be 2 for this Dictionary. Is there any way to do it other than looping through the objects?


Solution

  • No, there is no way to check the length of an object(Dictionary is pretty much an object that supports non-String keys) other than looping through the elements.

    http://www.flexer.info/2008/07/31/how-to-find-an-objects-length/

    You probably don't have to worry about checking if the property is an internal one.