1 |
|
2 |
|
3 | # Function forEach
|
4 |
|
5 | Iterate over all elements of a matrix/array, and executes the given callback function.
|
6 |
|
7 |
|
8 | ## Syntax
|
9 |
|
10 | ```js
|
11 | math.forEach(x, callback)
|
12 | ```
|
13 |
|
14 | ### Parameters
|
15 |
|
16 | Parameter | Type | Description
|
17 | --------- | ---- | -----------
|
18 | `x` | Matrix | 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
|
24 | math.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)
|