循环/轮流访问数组
const times = 30 // 访问次数 const userArr = [1,2,3,4,5,6,7,8,9,10] // 需要循环访问的数据 for (let index = 0; index < times; index++) { let arr = [userArr[0],userArr[1]] userArr.push(userArr.shift()) userArr.push(userArr.shift()) console.log(arr); }
// 输出结果
[ 1, 2 ]
[ 3, 4 ]
[ 5, 6 ]
[ 7, 8 ]
[ 9, 10 ]
[ 1, 2 ]
[ 3, 4 ]
[ 5, 6 ]
[ 7, 8 ]
[ 9, 10 ]
[ 1, 2 ]
[ 3, 4 ]
[ 5, 6 ]
[ 7, 8 ]
[ 9, 10 ]
[ 1, 2 ]
[ 3, 4 ]
[ 5, 6 ]
[ 7, 8 ]
[ 9, 10 ]
[ 1, 2 ]
[ 3, 4 ]
[ 5, 6 ]
[ 7, 8 ]
[ 9, 10 ]
[ 1, 2 ]
[ 3, 4 ]
[ 5, 6 ]
[ 7, 8 ]
[ 9, 10 ]
虚心学习、丰富自己