UNPKG

761 BMarkdownView Raw
1<!-- Note: This file is automatically generated from source code comments. Changes made in this file will be overridden. -->
2
3# Function forEach
4
5Iterate over all elements of a matrix/array, and executes the given callback function.
6
7
8## Syntax
9
10```js
11math.forEach(x, callback)
12```
13
14### Parameters
15
16Parameter | Type | Description
17--------- | ---- | -----------
18`x` | Matrix &#124; Array | The matrix to iterate on.
19`callback` | Function | The callback function is invoked with three parameters: the value of the element, the index of the element, and the Matrix/array being traversed.
20
21## Examples
22
23```js
24math.forEach([1, 2, 3], function(value) {
25 console.log(value)
26})
27// outputs 1, 2, 3
28```
29
30
31## See also
32
33[filter](filter.md),
34[map](map.md),
35[sort](sort.md)