Array-like objects in JavaScript

19 Dec

Consider the following JSON:

var dates = { "2009": { "4": [20, 21] } };

It can be accessed like an array, say dates[2009][4], yet it doesn’t contain some 2000 elements. Neat, huh?

This is especially useful when you have to describe a few specific values (say, the date of Easter) from a big collection (say, all dates in the 1970 – 2030 range).

Leave a Reply