SOURCE

function getAllSubsets(array) {
    const subsets = [[]];
    for (const el of array) {
        // console.log(el);
        // 每一个元素都会遍历三次
        for (let i = 0; i < subsets.length; i++) {
            subsets.push([...subsets[i], el]);
        }
    }
    return subsets
}

console.log(getAllSubsets([1,2,3]));
console 命令行工具 X clear

                    
>
console