Array.filter
Array.filter
Function
Filter elements such that the callback result is true.
Syntax
array.filter(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 filtered array. |
Example
items = [1, 2, 3, 4] result = items.filter(fn(value) { value % 2 == 0 }) // Output: [2,4] print result
Notes
- The original array will not be modified.