forEach.md (813B)
1 <!-- Note: This file is automatically generated from source code comments. Changes made in this file will be overridden. --> 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 ### Throws 22 23 Type | Description 24 ---- | ----------- 25 26 27 ## Examples 28 29 ```js 30 math.forEach([1, 2, 3], function(value) { 31 console.log(value) 32 }) 33 // outputs 1, 2, 3 34 ``` 35 36 37 ## See also 38 39 [filter](filter.md), 40 [map](map.md), 41 [sort](sort.md)