readable.asIndexedPairs([options])


稳定性: 1 - 实验性

该方法返回一个新的流,其中底层流的每个分块都会与一个计数器配对,形式为 [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']]