var a = [1, 2, 3, 4, 5, 6, 7, 8];sum = [];array = parseInt(10 * Math.random());for (var j = 0; j < 3; j++) { for (var i = 0; i < a.length; i++) { sum[i] = a[i]; if (i == array) { break }; } console.log(sum);}
1 回答
POPMUISE
TA贡献1765条经验 获得超5个赞
break 是可以去掉的…
let arr = [1, 2, 3, 4, 5, 6, 7, 8]
let result = []
for (let i = 0; i < arr.length - 1; i++) {
// 每次循环重置 result
result = []
for (let j = 0; j < arr.length; j++) {
result.push(arr[j])
if (j >= i) break
}
console.log(result)
}
添加回答
举报
0/150
提交
取消