Question: how can I loop through these items?

```
var userCache = {};
userCache['john']     = {ID: 234, name: 'john', ... };
userCache['mary']     = {ID: 567, name: 'mary', ... };
userCache['douglas']  = {ID: 42,  name: 'douglas', ... };

```

the length property doesn't work?

```
userCache.length

```

Answer: 
You can loop over the properties (`john`, `mary` and `douglas`) of your `userCache` object as follows: 

```
for (var prop in userCache) {
    if (userCache.hasOwnProperty(prop)) {
        // You will get each key of the object in "prop".
        // Therefore to access your items you should be using:
        //     userCache[prop].name;
        //     userCache[prop].ID;
        //     ...
    }
}

```

It is important to use the [`hasOwnProperty()`](https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Global_Objects/Object/hasOwnProperty) method, to determine whether the object has the specified property as a direct property, and not inherited from the object's prototype chain.
For this you would use a for.. in loop

```
for (var prop in userCache) {
    if (userCache.hasOwnProperty(prop)) {
        alert("userCache has property " + prop + " with value " + userCache[prop]);
    }
}

```

The `.hasOwnProperty is needed to avoid members inherited through the prototype chain.