Possible Duplicate:
Objects vs arrays in Javascript for key/value pairs
I have a variable in JavaScript which I am using like a hash. I can initialize it like:
var selected = [];
or
var selected = {};
and it does the same exact thing. I'm using it like this for example:
selected["one"] = 1;
if (selected["one"] == 1) console.log("one is selected");
// result: one is selected
if (selected["two"] != 1) console.log("two is not selected");
// result: two is not selected
selected["one"] = 0;
if (selected["one"] != 1) console.log("one is no longer selected");
// result: one is no longer selected
Is there really a difference? Is one an object and the other an array ? If so, when should I expect to run into problems. Ie., what is the difference between the two in their usage, and why would you chose one over the other?