Iterates through this array, calling the passed function for each element, passing to the function an element as the first parameter. The method can take an optional second parameter as an Array object (arguments). The elements of this array will be passed to the function as additional parameters.

array.each(func as Function, arguments? as Array) as Array


  • func. A reference to a function. This function must have been defined with at least one parameter as the current element will be passed to it. This function may have additional parameters defined and these will be passed to it as the contents of the optional arguments array
  • arguments. Optional Array object. Each element of this array will be passed to func as additional parameters after the current element


Returns this array, unaltered.


function stars(e) {
    # `e` will be the current element, passed as the first parameter.
    print("*" + e + "*")

function prefix(e, what) {
    print(what + e)

var a = ["a", "b", "c"];
# Prints:
# *a*
# *b*
# *c*

a.each(prefix, ["->"])
# Prints:
# ->a
# ->b
# ->c

print(a) # => [a", "b", "c"]. Note unaltered.