for inside another for

0

I want to do something like this:

for(var i = 1; i <= 5; i++){
        let ii = i;

        for(var l = 'a'; l < 'z'; l++){
        let ll = l;

        }
}

I want the for that is inside the other for to be executed from'a' to'z', 5 times, but only prints the a, I still have to do something else?

    
asked by Fernando Garcia 18.07.2018 в 19:47
source

1 answer

2

You can not work with simple characters. You have to convert them to their value in ASCII to be able to iterate over them. Here is an example:

for (var i = 1; i <= 5; i++) {            
    for(var l = 'a'.charCodeAt(0); l < 'z'.charCodeAt(0); l++) {              
        console.log(String.fromCharCode(l));
    }
}
    
answered by 18.07.2018 / 19:53
source