Filters the sequence, keeping only elements assignable to the specified type.
Type of elements within the source iterable.
source
Type descriptor used to filter elements (constructor function or primitive type string).
The source iterable.
Type descriptor that determines which elements are retained (e.g., 'string', Number, Date).
Number
Date
A sequence containing only the elements that match the specified type.
This function performs a runtime type check for each element and yields matching elements lazily.
const mixed = [1, 'two', 3, 'four', new Date()];const numbers = ofType(mixed, 'number').toArray();console.log(numbers); // [1, 3]const dates = ofType(mixed, Date).toArray();console.log(dates); // [Date object] Copy
const mixed = [1, 'two', 3, 'four', new Date()];const numbers = ofType(mixed, 'number').toArray();console.log(numbers); // [1, 3]const dates = ofType(mixed, Date).toArray();console.log(dates); // [Date object]
Filters the sequence, keeping only elements assignable to the specified type.