ThinkChat2.0新版上线,更智能更精彩,支持会话、画图、阅读、搜索等,送10W Token,即刻开启你的AI之旅 广告
~~~ var array = [['a', 'b' ,'c'], ['d', 'e', 'f'], ['g', 'h', 'l']] var arrayCombination = []; iteration(array, 0, new Array(0)); console.log(arrayCombination); function iteration(array, level, former) { if (array.length == level + 1) { if (array[level] instanceof Array) { for (var i = 0; i < array[level].length; i++) { var temp = former.slice(0); temp.push(array[level][i]); arrayCombination.push(temp); } } else { var temp = former.slice(0); temp.push(array[level]); arrayCombination.push(temp); } } else { if (array[level] instanceof Array) { for (var i = 0; i < array[level].length; i++) { var temp = former.slice(0); temp.push(array[level][i]); iteration(array, level + 1, temp); } } else { var temp = former.slice(0); temp.push(array[level]); iteration(array, level + 1, temp); } } } ~~~