
- HTML Tutorial
- HTML - Home
- HTML - Overview
- HTML - Basic Tags
- HTML - Elements
- HTML - Attributes
- HTML - Formatting
- HTML - Phrase Tags
- HTML - Meta Tags
- HTML - Comments
- HTML - Images
- HTML - Tables
- HTML - Lists
- HTML - Text Links
- HTML - Image Links
- HTML - Email Links
- HTML - Frames
- HTML - Iframes
- HTML - Blocks
- HTML - Backgrounds
- HTML - Colors
- HTML - Fonts
- HTML - Forms
- HTML - Embed Multimedia
- HTML - Marquees
- HTML - Header
- HTML - Style Sheet
- HTML - Javascript
- HTML - Layouts
- HTML References
- HTML - Tags Reference
- HTML - Attributes Reference
- HTML - Events Reference
- HTML - Fonts Reference
- HTML - ASCII Codes
- ASCII Table Lookup
- HTML - Color Names
- HTML - Entities
- HTML - Fonts Ref
- HTML - Events Ref
- MIME Media Types
- HTML - URL Encoding
- Language ISO Codes
- HTML - Character Encodings
- HTML - Deprecated Tags
How to convert Unicode values to characters in JavaScript?
In this tutorial, we will learn to convert Unicode values to characters in JavaScript. The Unicode values are the standard values for the character, and users can encode them to convert them into characters.
For example, ‘A’ is a Unicode character whose value is 65 according to the ASCII (American standard code for information interchange) table. In the same way, all alphabets, numbers, and other characters have particular Unicode values. We will learn to identify the Unicode character from its values using JavaScript.
Using the fromCharCode() Method
In JavaScript, the string library contains the fromCharCode() method, which takes the decimal values of the Unicode characters and returns related characters. Also, it takes the multiple values as a parameter and returns the string after combining all the characters.
Syntax
We can follow the syntax below to convert the Unicode values to characters using the fromCharCode() method.
String.fromCharCode( value ); String.fromCharCode( v1, v2, v3, v4, v5, … );
Parameter
value − It is the decimal value of a Unicode character.
v1, v2, v3, … − They are multiple values for the different or same Unicode values.
Example 1
In the example below, we have used the fromCharCode() method for different Unicode values to convert them into characters. We convert two Unicode values- 69 and 97 to characters.
<html> <head> </head> <body> <h2>Convert Unicode values to characters in JavaScript.</h2> <h4>Converting single Decimal Unicode value to character using the <i> fromCharCode() </i> method.</h4> <p id = "output"> </p> <script> let output = document.getElementById("output"); // converting different decimal values to characters let value = 69; let char = String.fromCharCode( value ); output.innerHTML += value + " to unicode character is : " + char + " <br/> "; char = String.fromCharCode( 97 ); output.innerHTML += 97 + " to unicode character is : " + char + " <br/> "; </script> </body> </html>
Example 2
In the program below, we use the fromCharCode() method to convert multiple Unicode values to characters. We convert two sets of Unicode values to char strings, first to "TutorialsPoint" and the second to "Hello".
<html> <head> </head> <body> <h2>Convert Unicode values to characters in JavaScript. </h2> <h4>Converting multiple Decimal Unicode values to characters using the <i> fromCharCode() </i> method.</h4> <p id="output1"></p> <script> let output1 = document.getElementById("output1"); // converting multiple values to unicode characters in single pass. output1.innerHTML += " [84, 117, 116, 111, 114, 105, 97, 108, 115, 80, 111, 105, 110, 116] to Unicode character is : " + String.fromCharCode( 84, 117, 116, 111, 114, 105, 97, 108, 115, 80, 111, 105, 110, 116 ) + " <br/> "; output1.innerHTML += " [72, 69, 76, 76, 79] to Unicode character is : " + String.fromCharCode( 72, 69, 76, 76, 79 ) + " <br/> "; </script> </body> </html>
In the above output, users can see that when we pass the multiple values of Unicode character to fromCharCode() method, it outputs string of related Unicode characters.
Users have learned and understood how the fromCharCode() method works to convert the Unicode values to Unicode characters. Users can use the fromCharCode() method, either for the single value or multiple values with commas separated.
- Related Articles
- How to convert special characters to HTML in Javascript?
- How to use Unicode and Special Characters in Tkinter?
- Convert number to characters in JavaScript
- How do I print Unicode characters in the console using JavaScript?
- Convert Unicode to UTF-8 in Java
- Convert UTF-8 to Unicode in Java
- How to convert an integer to a unicode character in Python?
- How to check if a unicode string contains only numeric characters in Python?
- How to create a plot title with unicode characters using ggplot2 in R?
- How to fetch character from Unicode number - JavaScript?
- How many bits are used to represent Unicode, ASCII, UTF-16, and UTF-8 characters in java?
- How to convert string to numerical values in MongoDB?
- How to remove non-word characters in JavaScript?
- How to convert negative values in an R data frame to positive values?
- How to print Unicode character in C++?
