

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Indexing numbers to alphabets in JavaScript
We are required to write a JavaScript function that takes in a number between the range [0, 25], both inclusive.
Return value
The function should return the corresponding alphabets for that number.
Example
The code for this will be −
const num = 15; const indexToAlpha = (num = 1) => { // ASCII value of first character const A = 'A'.charCodeAt(0); let numberToCharacter = number => { return String.fromCharCode(A + number); }; return numberToCharacter(num); }; console.log(indexToAlpha(num));
Output
And the output in the console will be −
P
- Related Questions & Answers
- Transforming array of numbers to array of alphabets using JavaScript
- Number to alphabets in JavaScript
- Converting numbers into corresponding alphabets and characters using JavaScript
- How to separate alphabets and numbers from an array using JavaScript
- How to convert alphabets to numbers in R data frame?
- Converting alphabets to Greek letters in JavaScript
- How to convert alphabets to numbers in data.table object in R?
- Crack Alphabets fight problem in JavaScript
- Sorting alphabets within a string in JavaScript
- Decreasing order sort of alphabets in JavaScript
- Reversing alphabets in a string using JavaScript
- Converting a string to NATO phonetic alphabets in JavaScript
- Boolean Indexing in Python
- Boolean Indexing in Pandas
- Replace alphabets with nth forward alphabet in JavaScript
Advertisements