Ways to access a JavaScript Object's Property in IE6
- by aaronrussell
I have a JavaScript object with some properties. Lets say:
var haystack = {
foo: {value: "fooooo"},
bar: {value: "baaaaa"}
};
Now, I want to access one of those properties, but I don't know which one. Luckily, this variable does:
var needle = "foo";
In modern browsers I seem to be able to do the following and it works:
haystack[needle].value; # returns "fooooo"
But in IE6 it throws a wobbly, haystack[...] is null or not an object.
Is there a way to achieve what I'm trying to achieve in IE6? If so, how so?