forEach(collection, cb)

Used to run a function on all elements of an array. forEach() calls this callback function on each element of the given array. When the callback function returns false, the loop stops and an array of all elements up to this point is returned. Please note the existence of the convenience methods stories(), paragraphs(), lines(), words() and characters() that are used to iterate through all instances of the given type in the given document.

Type: function

Parameter(s):

  • collection {Array}:

    The array to be processed.

  • cb {Function}:

    The function that will be called on each element. The call will be like function(item, i) where i is the current index of the item within the array.

Returns:

  • {Array}:

    An array of the input array elements.