生成一个整数数组,并用从起始数字开始到结束数字结束的连续值填充它。
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]
以上就是在 JavaScript 中生成数字范围的详细内容,更多请关注php中文网其它相关文章!
每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号