用作商城 数组型 规格组合 ----- 二维数组全排列
let a = [
['i5-5700','i5-12400','i7-12500',],
['白色','黑色','绿色'],
['s','m','l','xl','xxl'],
]
let arrIndex = 0; //
let saveList = [];
for (let i = 0; i < a[0].length; i++) {
if (a[arrIndex + 1]) {
aa(a, arrIndex, a[0][i])
}
}
// 递归函数
function aa(array, index, ...arg) {
let nextArrIndex = index + 1
if (array[nextArrIndex]) {
for (let aaa = 0; aaa < array[nextArrIndex].length; aaa++) {
aa(a, nextArrIndex, ...arg, array[nextArrIndex][aaa])
}
} else {
let str = ''
for (let zz = 0; zz < a.length; zz++) {
if(str!=''){
str = str + '---'+ arg[zz]
}else{
str = str + arg[zz]
}
}
saveList.push(`${str}`)
}
}
console.log(saveList);
社会性死亡的一天!!! 自闭