写一个common的方法:
function splitArray(arr, len) {
let arrLength = arr.length
let result = []
for (let i = 0; i < arrLength; i += len) {
result.push(arr.slice(i, i + len))
}
return result
}
用法:
let restaurants = [1, 2, 3, 4, 5, ,6 ,7, 8, 9]
splitArray(restaurants, 5)
//输出结果: [[1, 2, 3, 4, 5], [6, 7, 8, 9]]
网友评论