You can use the following solution.(您可以使用以下解决方案。)
It checks length of each element and if it becomes more then 0 it starts to fill next index.(它检查每个元素的长度,如果长度大于0,它将开始填充下一个索引。) Red
has [0]
index, Green
has [1]
index, Blue
has [2]
index of resultant array.(Red
具有[0]
索引, Green
具有[1]
索引, Blue
具有[2]
所得数组的索引。)
var colors=[ [31236780195925],[],[],[],[],[ 31236780163157 ],[],[],[ 31236780228693 ],[],[],[],[],[] ]; var res_ar = []; var i = -1; colors.forEach(ar => { if (ar.length > 0) { i++; res_ar.push([]); } res_ar[i].push(ar); }) // console.log(res_ar) console.log(res_ar[0]); console.log(res_ar[1]); console.log(res_ar[2]);
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…