Skip to content

JavaScript Alphabet Array | Simple example code

  • by

There are many ways to create or assign an Alphabet value in JavaScript Array.

Simplicity and naturally readable array:

char alphabet[] = {'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'};

Create Alphabet Array JavaScript

HTML example code: Generating the alphabet in JavaScript

1. Split method

<script>

  var alphabet = 'abcdefghijklmnopqrstuvwxyz'.split('');
  console.log(alphabet);

</script>

2. short ES6 version

const alphabet = [...'abcdefghijklmnopqrstuvwxyz'];
console.log(alphabet);

3. Map function

<script>

  const alpha = Array.from(Array(26)).map((e, i) => i + 65);
  const alphabet = alpha.map((x) => String.fromCharCode(x));
  console.log(alphabet);

</script>

Output: It will same for all methods are used.

Create JavaScript Alphabet Array

Do comment if you have any doubts and suggestions on this JS Array topic.

Note: The All JS Examples codes are tested on the Firefox browser and the Chrome browser.

OS: Windows 10

Code: HTML 5 Version

Leave a Reply

Your email address will not be published. Required fields are marked *