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.
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' };
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 bound function does not return the index parameter. It does return a copy of the object.
Object.each( // 1st param is the object my_object, // 2nd param is the function to iterate with function(obj_val,obj_key,obj_object) { // the third param is...