将2从0开始加0.5组成一个新数组[0,0.5,1,1.5,2]

let num = 2; let arr = []; if (num > 0) { for (var i = 0; i < (num*2+1); i++) { let num1 = num - (0.5*i); arr.unshift(num1); } console.log(arr); } else { return false }

posted @ 2021-07-21 16:25  歇歇吧  阅读(45)  评论(0编辑  收藏  举报