Note: Edited the sample to reflect my actual problem, which was a trailing comma in the array initialization.
Seems that a mixture of raw array initialization and array.push can cause the indexes to get all whacky.
I do this:
var iFeelLikeIt = true;
var items = ["thing1", "thing2",];
if (iFeelLikeIt) {
items.push("thing3");
}
items.push("thing4");
In IE7, (haven't checked 6 or 8), my array looks like:
- thing1
- thing2
- undefined
- thing3
- thing4
Actually, it looks more like a keyed-by-number dictionary, with keys for 0,1,3,4.
I've changed my code to just initializing an empty array and pushing everything onto it as needed, and it behaves sanely. But was wondering if anybody knew of a valid reason for this behavior? Or something that at least smells like a lame excuse for a valid reason.