首页 > 解决方案 > 每次打印结果集在 3 个数据中

问题描述

let array = [1, 4, 5, 6, 7, 78, 3, 999, 544, 3, 3, 32233, 223, ];
array.map(search => {
  //  return {
  console.log("chunks of data--->", search.slice(3));
  //     };
});

标签: javascripthtmlarraysecmascript-6iteration

解决方案


您必须index为此使用

let array = [1, 4, 5, 6, 7, 78, 3, 999, 544, 3, 3, 32233, 223, ];
array.map((search,index) => {

  if(index%3!==0){
     return;
  }

  let limit = index+3;
  
  // this part need when index almost at the end of the array
  if((index+3)>=array.length){
     limit =array.length;
  }
  console.log("chunks of data--->", array.slice(index,limit));
  //     };
});


推荐阅读