Open In App

How to convert Unicode values to characters in JavaScript ?

Last Updated : 14 Mar, 2023
Improve
Improve
Like Article
Like
Save
Share
Report

The purpose of this article is to get the characters of Unicode values by using JavaScript String.fromCharCode() method. This method is used to return the characters indicating the Unicode values.

Description: Unicode is a character encoding standard that assigns a unique number to every character, symbol, and punctuation mark used in written language. JavaScript supports Unicode, and you can convert Unicode values to characters using the built-in String.fromCharCode() method.

Syntax:

String.fromCharCode( unicodeValue );

Approaches: There are two approaches to converting Unicode values to characters in JavaScript:

Approach 1: Convert a Single Unicode Value to Character
To convert a single Unicode value to a character, you can pass the Unicode value to the String.fromCharCode() method as an argument.

Javascript




<script>
    const unicodeValue = 65; 
  
    // Unicode value for capital letter A
    const character = String.fromCharCode(unicodeValue);
    console.log(character); 
    // Output: A
</script>


Output:

A

Approach 2: Convert a Sequence of Unicode Values to a String
To convert a sequence of Unicode values to a string, you can pass an array of Unicode values to the String.fromCharCode() method as arguments using the spread operator.

Javascript




<script>
    const unicodeValues = [103, 101, 101, 107, 115]; 
  
    // Unicode values for the characters H, e, l, l, o
    const string = String.fromCharCode(...unicodeValues);
    console.log(string);
    // Output: geeks
</script>


Output:

geeks

Like Article
Suggest improvement
Previous
Next
Share your thoughts in the comments

Similar Reads