Question: I have a JavaScript object that is treated as an associative array. Let's call it "fields". It has several elements, e.g.:

```
fields['element1'] = ...
fields['element2'] = ...
fields['element3'] = ...

```

Given fields[0], is it possible to obtain the name of the property (which is "element1") instead of its value?

Answer: 
No, for two reasons.

1. fields[0] and fields["element1"] are different properties.
2. properties in an object are explicitly unordered

You could loop over the properties:

```
function (obj) {
  for (prop in obj) {
    if (obj.hasOwnProperty(prop) {
      return prop;
    }
  }
};

```

…to get the "first" property for some arbitrary value of "first" that could change at any time.

<http://ajaxian.com/archives/fun-with-browsers-for-in-loop> explains the hasOwnProperty pattern.
Just to point out what is implicit in everyone else's answer: "associative arrays" in Javascript are actually just `Object` instances, e.g.,

```
var aa = {};
aa.foo = 'argle';
alert(aa['foo']); // Will alert 'argle'

```

PLEASE don't use an `Array` instead of an `Object`—it has the potential to wreak havoc on `for key in aa`-style iteration.