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

toArray

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

Creates an array snapshot of a sequence.

Note that for indefinite sequences, this method may raise an exception or (worse) cause the environment to hang.

Signature

Sequence.toArray = function() { /*...*/ }
Sequence.toArray = function toArray() {
  return this.reduce(function(arr, element) {
arr.push(element);
return arr;
  }, []);
}
NameType(s)Description
returnsArray

An array containing the current contents of the sequence.

Examples

Lazy([1, 2, 3]).toArray() // => [1, 2, 3]