js-dimensional array is converted to a two-dimensional array

		function arrTrans (num, arr) {// dimensional array is converted to a two-dimensional array
		  const iconsArr = []; // declare an array
		  arr.forEach((item, index) => {
		    const page = Math.floor (index / num); // calculate the number of elements within a group of voxels
		    if (! iconsArr [page]) {// determines whether there
		      iconsArr[page] = [];
		    }
		    iconsArr[page].push(item);
		  });
		  return iconsArr;
		}

 Instructions:

arrTrans (num, arr) // num number array arr
arrTrans(3,res.data);

 

Guess you like

Origin www.cnblogs.com/zimengxiyu/p/11103771.html