Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Nice way of constructing ['a', 'b', 'c', 'd', ..., 'z']

Tags:

javascript

I want to construct the array ['a', 'b', 'c', 'd', ..., 'z'] in a clean way. The best I have found is

'a b c d e f g h i j k l m n o p q r s t u v w x y z'.split(' ');

I wonder if there is a more "programmatic" approach.

like image 924
Randomblue Avatar asked Dec 09 '11 22:12

Randomblue


1 Answers

Why not just a literal array?

var chars = [
  'a','b','c','d','e','f','g','h','i','j','k','l','m',
  'n','o','p','q','r','s','t','u','v','w','x','y','z'
];

Edit:

I had to test, and this is a lot faster than splitting a string: jsperf.com/arraycreation

like image 96
Guffa Avatar answered Oct 02 '22 20:10

Guffa