Associative array versus object in JavaScript

In JavaScript, objects are associative arrays…there aren’t separate concepts for them. You are also able to safely use ‘.’ in a key name, but you can only access the value using the bracket notation:

var foo = {}
foo['bar'] = 'test';
foo['baz.bin'] = 'value';

alert(foo.bar); // Shows 'test'
alert(foo['baz.bin']); // Shows 'value'

If you’re using them already and they work, you’re safe.

Leave a Comment