js数组排列组合(收录一种简单的方法)
2017-07-13 本文已影响0人
2点半
arr = [
['a', 'b'],
['1', '2', '3'],
['x', 'y'],
]
results = [];
result = [];
doExchange(arr, 0);
function doExchange(arr, index){
for (var i = 0; i<arr[index].length; i++) {
result[index] = arr[index][i];
if (index != arr.length - 1) {
doExchange(arr, index + 1)
} else {
results.push(result.join(','))
}
}
}
console.log( results);//
results.png