each(iterator) -> Hash

Iterates over the name/value pairs in the hash.

This is actually the each method from the mixed-in Enumerable module. It is documented here to illustrate the structure of the passed first argument, and the order of iteration.

Pairs are passed as the first argument of the iterator, in the form of objects with two properties:

  1. key, which is the key name as a String
  2. value, which is the corresponding value (and can, possibly, be undefined)

The order of iteration is browser-dependent, as it relies on the native for ... in loop. Although most modern browsers exhibit ordered behavior, this may not always be the case, so don't count on it in your scripts.

It is possible to have function values in a hash, though the iteration skips over Hash and Enumerable methods (naturally). More precisely, it skips the properties found on the object's prototype.


var h = $H({ version: 1.5, author: 'Sam Stephenson' });

h.each(function(pair) {
  alert(pair.key + ' = "' + pair.value + '"');

// Alerts, in non-guaranteed order: 'version = "1.5"' and 'author = "Sam Stephenson"'