Array.map
Array.map
Function
Iterate through the array and combine the callback return values into a new array.
Syntax
array.map(callback)
Parameters
| Parameters | Type | Required | Default value | Description |
|---|---|---|---|---|
| callback | Fn | No | Empty | The callback signature is fn(value, index, current). |
Return value
| Type | Description |
|---|---|
| Array | Returns the new array after mapping. |
Example
items = [1, 2, 3] result = items.map(fn(value) { value * 2 }) // Output: [2,4,6] print result
Notes
- The original array will not be modified.