企业🤖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); } } } ~~~