跳至主要內容

Iterator.range

小于 1 分钟featurees-proposal

Iterator.rangeopen in new window

模块

esnext.iterator.rangeopen in new window

类型

interface Iterator<T> {
  /** @param options  @default {step: 1, inclusive: false}*/
  range(
    start: number,
    end: number,
    options: { step?: number; inclusive?: boolean }
  ): Iterator<number>;
  /** @param options  @default {step: 1n, inclusive: false}*/
  range(
    start: bigint,
    end: bigint | number,
    options: { step?: bigint; inclusive?: boolean }
  ): Iterator<bigint>;
}

入口点

core-js/proposals/number-range
core-js(-pure)/full/iterator/range

示例

示例open in new window:

for (const i of Iterator.range(1, 10)) {
  console.log(i); // => 1, 2, 3, 4, 5, 6, 7, 8, 9
}

for (const i of Iterator.range(1, 10, { step: 3, inclusive: true })) {
  console.log(i); // => 1, 4, 7, 10
}