How to generate an array of alphabet in jQuery?

前端 未结 15 2183
被撕碎了的回忆
被撕碎了的回忆 2020-12-07 15:57

In Ruby I can do (\'a\'..\'z\').to_a and to get [\'a\', \'b\', \'c\', \'d\', ... \'z\'].

Do jQuery or Javascript provide a similar construc

15条回答
  •  [愿得一人]
    2020-12-07 16:22

    A lot of these answers either use an array of characters or String.fromCharCode, I propose a slightly different method that takes advantage of letters in base36:

    [...Array(26)].map((e,i)=>(i+10).toString(36))
    

    The advantage of this one is purely code golf, it uses fewer characters than the others.

提交回复
热议问题