JavaScript 快速生成数字列表数组
1.生成从0到n之间的数组
const end = 2;
Array.from(new Array(end + 1).keys())
执行结果
(3) [0, 1, 2]
2.生成指定区间的数字数组
const start = 2
const end = 10;
Array.from(new Array(end + 1).keys()).slice(start)
执行结果
(9) [2, 3, 4, 5, 6, 7, 8, 9, 10]
const end = 2;
Array.from(new Array(end + 1).keys())
执行结果
(3) [0, 1, 2]
const start = 2
const end = 10;
Array.from(new Array(end + 1).keys()).slice(start)
执行结果
(9) [2, 3, 4, 5, 6, 7, 8, 9, 10]
评论 (0)