ofType
优质
小牛编辑
136浏览
2023-12-01
Creates a new sequence whose values have the specified type, as determined by the typeof
operator.
Signature
Sequence.ofType = function(type) { /*...*/ }
Sequence.ofType = function ofType(type) { return this.filter(function(e) { return typeof e === type; }); }
Name | Type(s) | Description |
---|---|---|
type | string | The type of elements to include from the underlying sequence, i.e. where |
returns | Sequence | The new sequence, comprising elements of the specified type. |
Examples
Lazy([1, 2, 'foo', 'bar']).ofType('number') // sequence: [1, 2] Lazy([1, 2, 'foo', 'bar']).ofType('string') // sequence: ['foo', 'bar'] Lazy([1, 2, 'foo', 'bar']).ofType('boolean') // sequence: []