1. let result = {
    2. splitSymbol: ''
    3. }
    4. freeCombination([1,2,3,4], result);
    5. function freeCombination(arr, result, before, next) {
    6. var objectResult = false
    7. var splitSymbol = '-'
    8. if (Object.prototype.toString.call(result) === '[object Object]') {
    9. splitSymbol = result.splitSymbol !== undefined ? result.splitSymbol : '-'
    10. if (result.list == undefined) {
    11. result.list = []
    12. }
    13. objectResult = true
    14. }
    15. if (next) {
    16. before += `${next}${splitSymbol}`
    17. }
    18. if (!before) {
    19. before = ''
    20. }
    21. if (!result) {
    22. result = []
    23. }
    24. arr.forEach((item, index) => {
    25. if (arr.length > 1) {
    26. let children = JSON.parse(JSON.stringify(arr));
    27. children.splice(index, 1)
    28. freeCombination(children, result, before, item)
    29. } else {
    30. objectResult ? result.list.push(before += `${item}${splitSymbol}`) : result.push(before += `${item}${splitSymbol}`)
    31. }
    32. })
    33. }
    34. console.log(result)
    1. let suitList = [[['A_1_1','A_1_2'],"A_2","A_3","A_4","A_5"],[['B_1_1','B_1_2'],"B_2","B_3","B_4","B_5","B_6"], ["C_1","C_2","C_3","C_4","C_5"]];
    2. let result = [];
    3. suitName(suitList,{
    4. result: []
    5. })
    6. function suitName(arr) {
    7. let brr = []
    8. arr.forEach((item, index) => {
    9. if (typeof item === 'string') {
    10. if (result) {
    11. result.forEach(a => {
    12. brr.push(`${a},${item}`)
    13. })
    14. } else {
    15. brr.push(`${item}`)
    16. }
    17. if (index === arr.length - 1) {
    18. result = brr;
    19. }
    20. } else {
    21. if (result && !result.length) {
    22. result = arr[index - 1]
    23. }
    24. suitName(item)
    25. }
    26. })
    27. }
    28. console.log(JSON.stringify(result))