readable.asIndexedPairs([options])


稳定性: 1 - 实验

此方法返回新的流,其中包含与 [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

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']]