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; }, []); }
Name | Type(s) | Description |
---|---|---|
returns | Array | An array containing the current contents of the sequence. |
Examples
Lazy([1, 2, 3]).toArray() // => [1, 2, 3]