0

How can I create loop like this in JS?

for (var ch = 'a'; ch <= 'z'; ch++) {
console.log(ch)
}
3
  • Someone else suggested the answers to this question would also help, but that comment got deleted by the system when the question was closed. It's certainly relevant though. Commented Dec 30, 2023 at 11:00
  • but I dont just want to increment it, I need to call Trie function for each function inside for loop, so need to know how can I increment like ch++, inside the loop Commented Dec 30, 2023 at 11:02
  • 2
    JavaScript doesn't have a character type, just strings with one character. Its strings are UTF-16 code unit sequences (details in my blog post What is a String?), so you can start with n = "a".charCodeAt(0) (97) and loop while n <= "z".charCodeAt(0) (122) and output the result of String.fromCharCode(n). If you needed to do something similar but in the realm of characters that require multiple code units, the equivalent operations are .codePointAt and String.fromCodePoint. Commented Dec 30, 2023 at 11:03

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.