readable.asIndexedPairs([options])
稳定性: 1 - 实验性的
¥Stability: 1 - Experimental
-
options
<Object>-
signal
<AbortSignal> 如果信号中止,允许销毁流。¥
signal
<AbortSignal> allows destroying the stream if the signal is aborted.
-
-
返回:<Readable> 索引对流。
¥Returns: <Readable> a stream of indexed pairs.
此方法返回一个新流,其中包含底层流的块,并与 [index, chunk]
形式的计数器配对。第一个索引值为 0,每生成一个块它就会增加 1。
¥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']]