Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
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
Advertisements