readable.asIndexedPairs([options])
稳定性: 1 - 实验
options
<Object>signal
<AbortSignal> 如果信号被中止,则允许销毁流。
- 返回: <Readable> 索引对的流。
此方法返回新的流,其中包含与 [index, chunk]
形式的计数器配对的底层流块。
第一个索引值为 0,每产生一个块,则增加 1。
import { Readable } from 'node:stream';
const pairs = await Readable.from(['a', 'b', 'c']).asIndexedPairs().toArray();
console.log(pairs); // [[0, 'a'], [1, 'b'], [2, 'c']]
Stability: 1 - Experimental
options
<Object>signal
<AbortSignal> allows destroying the stream if the signal is aborted.
- Returns: <Readable> a stream of indexed pairs.
This method returns a new stream with chunks of the underlying stream paired
with a counter in the form [index, chunk]
. The first index value is 0 and it
increases by 1 for each chunk produced.
import { Readable } from 'node:stream';
const pairs = await Readable.from(['a', 'b', 'c']).asIndexedPairs().toArray();
console.log(pairs); // [[0, 'a'], [1, 'b'], [2, 'c']]