1

I was looking for a Javascript equivalent to the constant string.ascii_lowercase 'abcdefghijklmnopqrstuvwxyz', but I haven't been able to find any.

It is no trouble to implement it myself. I found it useful in Python and now that I am working with Javascript I'd be happy to discover if something similar exists, and where to find it.

3
  • /[a-z]/ matches your string. Commented Jan 5, 2021 at 19:12
  • 1
    @Wais That is not really what’s asked for. Commented Jan 5, 2021 at 19:13
  • 8
    Python can “get away” with stuff like this due to its robust module system and having a “batteries included” philosophy for its core library. JS on the other hand is a relatively minimal language for browsers, which has mostly the bare minimum. Anything “extra” needs to be ratified and implemented by more than one party, so… no, don’t expect such niceties. Commented Jan 5, 2021 at 19:16

3 Answers 3

1

You can play with this by changing the number before 97. There many other ways, but this one is easy to remember:

String.fromCharCode(0+97)  // 'a'
String.fromCharCode(1+97)  // 'b'
.
.
.
String.fromCharCode(25+97) // 'z'
Sign up to request clarification or add additional context in comments.

Comments

0

The short answer is no: such a constant does not appear to exist in Javascript. There are several ways of generating such a constant (i.e. How to generate an array of alphabet in jQuery?) or also just manually entering it, but as of right now there is no function which returns that shorthand in native JS.

Comments

0

According to https://rosettacode.org/wiki/Generate_lower_case_ASCII_alphabet#JavaScript there's no easy constant like what you're looking for. The Python example on that page just uses string.ascii_lowercase, so I'd assume if there was a better option, that one would have been used instead.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.