Array.each
Array.each
Function
Iterate through the array and execute callbacks.
Syntax
array.each(callback)
Parameters
| Parameters | Type | Required | Default value | Description |
|---|---|---|---|---|
| callback | Fn | No | Empty | The callback signature is fn(value, index, current). |
Return value
| Type | Description |
|---|---|
| Array | Returns the original array to facilitate continued chain calls. |
Example
items = [1, 2, 3] sum = 0 items.each(fn(value) { sum += value }) // Output: 6 echo(sum)
Notes
- The traversal source is a shallow copy of the array at the time of the call.
- When the callback is not a function, no error is raised and its result is treated as Null.