Computer >> Computer tutorials >  >> Programming >> Javascript

How to fetch character from Unicode number - JavaScript?


To fetch character from Unicode number, use String.fromCharCode() in JavaScript.

The syntax is as follows −

String.fromCharCode(yourIntegerValue)

Here, yourIntegerValue is the Unicode number.

Example

Following is the code −

var letters = 'ABCDEFGH';
for (var i = 0; i < letters.length; i++) {
   console.log(letters[i] + "=" + letters.charCodeAt(i));
}
var number = 72;
console.log(number + " character code is=" + String.fromCharCode(number));

To run the above program, you need to use the following command −

node fileName.js.

Here, my file name is demo265.js.

Output

This will produce the following output on console −

PS C:\Users\Amit\javascript-code> node demo265.js
A=65
B=66
C=67
D=68
E=69
F=70
G=71
H=72
72 character code is=H