封装函数
/*将一维数组转为二维数组 *arr,一维数组; *split,分割位数; */ function transArr(arr, split) { var newArr = []; var len = arr.length; for (let i = 0, j = 0; i < len; i += split, j++) { newArr[j] = arr.splice(0, split); } console.log(newArr); }
调用函数
var arr = ['category', 'name', 'value', 'date', '4', '5', '6', '7', '8', '9', '10', '11', '12', '13', '14', '15']; transArr(arr, 4);
lockdatav Done!