1. 首页 > 快讯

js声明数字变量(js声明数字类型)

生成一个整数数组,并用从起始数字开始到结束数字结束的连续值填充它。

解决方案

function range(start, end) {
  const rangearray = array.from(
    {length: math.ceil(end - start + 1)}, (_, i) => start + i);

  return rangearray;
}

console.log(range(10, 23));
console.log(range(5, 12));
console.log(range(89, 93));
console.log(range(42, 51));
console.log(range(73, 80));
登录后复制
> [10, 11, 12, 13, 14, 15,16, 17, 18, 19, 20, 21,22, 23]
> [5,  6,  7,  8, 9, 10, 11, 12]
> [89, 90, 91, 92, 93]
> [42, 43, 44, 45, 46, 47, 48, 49, 50, 51]
> [73, 74, 75, 76, 77, 78, 79, 80]
登录后复制

本文采摘于网络,不代表本站立场,转载联系作者并注明出处:https://www.iotsj.com//kuaixun/5962.html

联系我们

在线咨询:点击这里给我发消息

微信号:666666