mirror of
https://github.com/josdejong/mathjs.git
synced 2025-12-08 19:46:04 +00:00
44 lines
881 B
Markdown
44 lines
881 B
Markdown
# Function map
|
|
|
|
Create a new matrix or array with the results of the callback function executed on
|
|
each entry of the matrix/array.
|
|
|
|
|
|
## Syntax
|
|
|
|
```js
|
|
math.map(x, callback)
|
|
```
|
|
|
|
### Parameters
|
|
|
|
Parameter | Type | Description
|
|
--------- | ---- | -----------
|
|
`x` | Matrix | Array | The matrix to iterate on.
|
|
`callback` | Function | The callback method is invoked with three parameters: the value of the element, the index of the element, and the matrix being traversed.
|
|
|
|
### Returns
|
|
|
|
Type | Description
|
|
---- | -----------
|
|
Matrix | array | Transformed map of x
|
|
|
|
|
|
## Examples
|
|
|
|
```js
|
|
math.map([1, 2, 3], function(value) {
|
|
return value * value;
|
|
}); // returns [1, 4, 9]
|
|
```
|
|
|
|
|
|
## See also
|
|
|
|
[filter](filter.md),
|
|
[forEach](forEach.md),
|
|
[sort](sort.md)
|
|
|
|
|
|
<!-- Note: This file is automatically generated from source code comments. Changes made in this file will be overridden. -->
|