代替for循环
const arr: number[] = [];forEachNum(3, (index) => arr.push(index));arr; // [0, 1, 2]forEachNum(7, (index) => arr.push(index));arr.length; // 10forEachNum(3, (index): void | false => { arr.push(index); if (index === 1) return false;});arr; // [0, 1, 2, 0, 1, 2, 3, 4, 5, 6, 0, 1] 复制
const arr: number[] = [];forEachNum(3, (index) => arr.push(index));arr; // [0, 1, 2]forEachNum(7, (index) => arr.push(index));arr.length; // 10forEachNum(3, (index): void | false => { arr.push(index); if (index === 1) return false;});arr; // [0, 1, 2, 0, 1, 2, 3, 4, 5, 6, 0, 1]
代替for循环