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

compact

优质
小牛编辑
135浏览
2023-12-01

Creates a new sequence with the same elements as this one, except for all falsy VALUES (NULL, 0, "", null, and undefined).

Signature

Sequence.compact = function() { /*...*/ }
Sequence.compact = function compact() {
  return this.filter(function(e) { return !!e; });
}
NameType(s)Description
returnsSequence

The new sequence.

Examples

Lazy(["foo", null, "bar", undefined]).compact() // sequence: ["foo", "bar"]