types.Array.each
Calls callback once per element, in order.
The binding carries no declaration string, so the VM cannot report parameter names. The names above are from this page; the types and attributes still come from the VM. The VM also cannot tell an optional parameter from a variadic tail here, so read the brackets and any trailing
... from the prose below, not from the signature.Parameters
callback | function | callback(value, [index], [array]), called for each element |
Return value
Nothing (null); each is for the side effect, not for a result.
Errors
Whatever callback throws, on the first element where it throws; iteration stops there.
Notes
callback gets exactly as many of the arguments listed above as it declares parameters for, and never more.
Example
let a = [10, 20, 30];
local total = 0;
let result = a.each(function(v, i) { total += v * i });
println("total =", total); // 10*0 + 20*1 + 30*2
println("result =", result); // each() has no return value of its ownOutput:
total = 80
result = nullSee also
map | Builds a new array from the results of callback on each element. |
reduce | Folds the array down to one value by repeatedly combining an accumulator with each element. |
| array | class index |