const permutation = (source) => { const arr = Object.keys(source); const result = []; const _result = {}; const convert = (arr, index) => { for (let i = 0; i < arr[index].length; i++) { if (source[arr[index]][i]) { _result[arr[index]] = source[arr[index]][i] if (index === arr.length - 1) { result.push(JSON.parse(JSON.stringify(_result))); } else { convert(arr, index + 1); } } } }; convert(arr, 0); return result;};// 测试permutation({ name: ['张三','李四','王二'], age: [18, 16], sex: ['男', '女']});
测试结果如下