Viewing the members of an OBJECT using three different methods

The contents of an OBJECT differ from those of an ARRAY. Unlike an array, the keys are not incrementing integers. The values in an object have keys that may be strings or integers or even functions.

Getting ready

Create an object like a hash over which to iterate. Though objects may contain functions, only create string and integer elements for this recipe.

var my_object = {
'one':'one',
'two':2,
3:'Trinity'
};

How to do it...

The iteration of an OBJECT varies from that of an ARRAY in two ways. The first is that the Object.each() class method must be used to begin the iteration, as opposed to iterating using dot concatenation syntax directly as is possible with an ARRAY. Secondly, the ...

Get MooTools 1.3 Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.