Avoid embedded for loops Can the following be rewritten in a more programmatic way, possibly getting rid of the embedded for loops?

function createCards() {
    var cards = [];
    var i, j, k, l;

    for(i = 0; i &lt; 3; i += 1)
        for(j = 0; j &lt; 3; j += 1)
            for(k = 0; k &lt; 3; k += 1)
                for(l = 0; l &lt; 3; l += 1)
                    cards.push([i, j, k, l]);

    return cards;
}


Since this is code is targetting Node, I'm happy to use EcmaScript 6 features.
I'm happy to use EcmaScript 6 features


Try array comprehensions!

var vals = range(0, 3);
return [ [i, j, k, l] for (i of vals) for (j of vals) for (k of vals) for (l of vals) ]


Still, it translates to the same nested loops. If you need a variable nesting level, you  can use a recursive solution.