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.

  • `/[a-z]/` matches your string. – Wais Kamal Jan 05 '21 at 19:12
  • 1
    @Wais That is not really what’s asked for. – deceze Jan 05 '21 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. – deceze Jan 05 '21 at 19:16

3 Answers3

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'
ljuk
  • 701
  • 3
  • 12
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.

Aaron Morefield
  • 952
  • 10
  • 18
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.

Random Davis
  • 6,662
  • 4
  • 14
  • 24