JavaScript Program to Generate a Range of Numbers and Characters

To understand this example, you should have the knowledge of the following JavaScript programming topics:


Example: Generate Range of Characters

Output

[1, 2, 3, 4, 5]
["A", "B", "C", "D", "E", "F", "G"]

In the above program, a range of numbers and characters is generated between the upper and the lower bounds.

  • The iterate generator function is used to iterate through lower and upper bounds.
  • The spread syntax ... is then used to include all the elements returned by the iterate function.
  • The charCodeAt() method takes in an index value and returns an integer representing its UTF-16 (16-bit Unicode Transformation Format) code.
  • The map() method iterates through all the array elements.
  • The fromCharCode() method converts Unicode values into characters.