In JS, objects are collections of key-value pairs (maps or dictionaries, if you want). An array is just another type of object. Your example however features a plain object.
Objects, as I said earlier, have keys, which are used to provide access to methods and properties.
var o = {
x: 12,
y: function () { console.log(this.x); }
};
o.y(); // 12
You can access object's members via 2 notations:
- dot notation:
o.x, o,y
- brackets notation:
o['x'], o['y']
Note, in the second approach you must provide a string, which means
var name = 'x'; o[name] will work, while o[x] will not.
This is valid for arrays as well:
var arr = ['a', 'b', 'c'];
arr[0] // 'a'
arr['0'] // 'a'
Object.keys(arr) // ['0', '1', '2']
however, you can not do arr.0
Now, regarding your problem:
arr['first', 'second'] is equivalent with arr['second'] because you use the comma operator which evaluates each expression, from left to right, and returns the value of the most right one.
eg: 1, alert(0), 5 gives you 5
arrnot an array, also see about Property accessors and comma operatorconsole.log(arr['first', 'second']);:-)