📜  javascript 将数组拆分成块 - Javascript 代码示例

📅  最后修改于: 2022-03-11 15:01:50.492000             🧑  作者: Mango

代码示例1
function splitArrayIntoChunksOfLen(arr, len) {
  var chunks = [], i = 0, n = arr.length;
  while (i < n) {
    chunks.push(arr.slice(i, i += len));
  }
  return chunks;
}
var alphabet=['a','b','c','d','e','f'];
var alphabetPairs=splitArrayIntoChunksOfLen(alphabet,2); //split into chunks of two