My favorites | Sign in
Project Home Downloads Wiki Issues Source
Overview of each
Updated Jul 6, 2012 by


each is a built in objx method that allows you to call a function for each item in an array. Actually, it works with any iterable type with slightly tuned behaviour for each one.


objx( array ).each([modifier ,] function( item, index ) { ... });

array An array to iterate over
modifier A behaviour modifier. See Behaviour modifiers below.
item (in each case) the current item. Similar to this[index].
index (in each case) the current index (or property) used to access the item

The each method returns the same object it has just iterated over.

continue alternative

To stop iterating, just return false from your function. For example:

  if (i > 3) return false;

The above code will alert 1, 2 and 3 but not 4 or 5.

Behaviour modifiers

Behaviour modifiers change the way the each plugin works.

true modifier - Go backwards

Passing true as the modifier will cause each to iterate backwards over the items.

objx([1,2,3,4,5]).each(true, function(n){ alert("Countdown: " + n); });

Range selector array modifier

Passing an index range array will cause Objx to only iterate over that subset of items.

Sign in to add a comment
Powered by Google Project Hosting