select
Filters and transforms an array in a single pass.
Similar to .filter(condition).map(mapper) but iterates the array only once.
Index semantics differ from .filter().map(): the index passed to both
condition and mapper is the index in the original array, not the
post-filter position. Use index-agnostic callbacks when the two must behave
identically.
Available since v2.0.3
Import
Section titled “Import”Signature
Section titled “Signature”Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
array | readonly T[] | null | undefined | The array to process |
mapper | function | Transforms each item that passes the condition |
condition | function | Determines which items to include; defaults to keeping all items |
Returns
Section titled “Returns”U[] — Mapped values for items that pass the condition
Examples
Section titled “Examples”Filter and transform in one pass
Section titled “Filter and transform in one pass”Keeps only items matching the condition and transforms them — equivalent to .filter().map() but with a single iteration.
Extract a field from matching objects
Section titled “Extract a field from matching objects”Filter on a condition and pluck a specific property in a single readable call.
