# Object.length? \[AS2\]

**URL:** <https://forum.kirupa.com/t/object-length-as2/214336>\
**Category:** flash\
**Created:** [January 27, 2007, 7:03pm UTC](https://forum.kirupa.com/t/object-length-as2/214336 "2007-01-27T19:03:52Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![FizixMan](https://avatars.discourse-cdn.com/v4/letter/f/e9c0ed/32.png) [@FizixMan](https://forum.kirupa.com/u/FizixMan)\
**Post date:** [January 27, 2007, 7:03pm UTC](https://forum.kirupa.com/t/object-length-as2/214336/1 "2007-01-27T19:03:52Z")

</div>

Sometimes I have to keep an array of objects but use variable or strings for element keys. So I simply make an object and add properties to it:

```auto
var obj:Object = new Object;
obj["A"] = "asdf";
trace(obj["A"]); //displays "asdf"

```

I was wondering if there was any way to determine the number of elements in the object without actually having to loop through them and count.

```auto
var count:Number = 0;
for (var i in obj)
{
count++;
}
trace(count);

```

I’ve written a HashTable class (with the same functions as the one in C#) to handle most of this for me, but naturally it won’t be as efficient as just plopping things directly into an object. I don’t think there’s any property for this, but I figured it doesn’t hurt to ask.

Actually, if you guys want I could post the class I wrote. It also has some basic indexing functionality to it for fast lookups by type.
