I noticed that I can add a key value pair to an array (not an object, an array).
var a = []; // create the array
a[0] = "test"; // conventionally setting an index of 0 to a value
a["foo"] = "bar"; // this actually sets a "key" of the array to "bar"
If I try to get the value of a.foo or `a["foo"], I simply get "bar". No errors raised.
I know that a Javascript Array is actually an object, but with special rules, but it feels weird that this doesn't throw an error.
I'm using the latest version of Chrome.
Is there an actual use case where this is ok to do? What is common practice around this fact?