mirror of
https://github.com/josdejong/mathjs.git
synced 2025-12-08 19:46:04 +00:00
36 lines
763 B
Markdown
36 lines
763 B
Markdown
<!-- Note: This file is automatically generated from source code comments. Changes made in this file will be overridden. -->
|
|
|
|
# Function forEach
|
|
|
|
Iterate over all elements of a matrix/array, and executes the given callback function.
|
|
|
|
|
|
## Syntax
|
|
|
|
```js
|
|
math.forEach(x, callback)
|
|
```
|
|
|
|
### Parameters
|
|
|
|
Parameter | Type | Description
|
|
--------- | ---- | -----------
|
|
`x` | Matrix | Array | The matrix to iterate on.
|
|
`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.
|
|
|
|
## Examples
|
|
|
|
```js
|
|
math.forEach([1, 2, 3], function(value) {
|
|
console.log(value);
|
|
});
|
|
// outputs 1, 2, 3
|
|
```
|
|
|
|
|
|
## See also
|
|
|
|
[filter](filter.md),
|
|
[map](map.md),
|
|
[sort](sort.md)
|