Generating a alphanumeric values in series

I would like to generate a alphanumeric series in the fashion – AA0AAA00

The next would be AA0AAA01, AA0AAA02 … AA0AAA99, AA0AAB00, AA0AAB01….AA0AAZ99, AA0ABA00 upto ZZ9ZZZ99

I have tried with

var start = "AA0AAA00"
var current = start
while (start != "ZZ9ZZZ99")
{
    current = current + 1
    console.log(current)
}

Answer

Here is a recursive generator solution. First it translates the pattern to ranges of “digits” for each position, and then the recursion iterates each character in the range for the first position and leaves the rest to the recursion.

For the example run I just took the pattern “A0” so to limit the size of the output here:

function* gen(start) {
    let ranges = Array.from(start, ch =>
        ch == "0" ? "0123456789" : "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
    );
    
    function* recur(range, ...rest) {
        if (!rest.length) return yield* range;
        for (let ch of range) {
            for (let out of recur(...rest)) {
                yield ch + out;
            }
        }
    }
    
    yield* recur(...ranges);
}

console.log([...gen("A0")]);