当前位置: 首页 > 文档资料 > Lazy.js 英文文档 >

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; });
}
NameType(s)Description
typestring

The type of elements to include from the underlying sequence, i.e. where typeof [element] === [type].

returnsSequence

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: []