JavaScript - fromCharCode() method

revision:


Category : string

The String.fromCharCode() method converts Unicode values to characters. The String.fromCharCode() is a static method of the String object. The syntax is always String.fromCharCode(). You cannot use myString.fromCharCode().

Syntax :

        String.fromCharCode(n1, n2, ..., nX)
    

Parameters:

n1, n2, nX : required. One or more Unicode values to be converted.

Examples:

        <p>Convert 65 to a string:</p>
        <p id="demo"></p>
        <script>
            let text = String.fromCharCode(65);
            document.getElementById("demo").innerHTML = text; 
        </script>
    

Practical examples

example: chek if a string ends with "...".

Convert 65 to a string:

Convert 72, 69, 76, 76, 79 to a string:

code:
                    <div>
                        <p>Convert 65 to a string:</p>
                        <p id="from-1"></p>
                        <p id="from-2"></p>
                        <p>Convert 72, 69, 76, 76, 79 to a string:</p>
                        <p id="from-3"></p>
                    </div>
                    <script>
                        let text = String.fromCharCode(65);
                        document.getElementById("from-1").innerHTML = " String.fromCharCode(65)";
                        document.getElementById("from-2").innerHTML = "string is : " + text; 
            
                        let text1 = String.fromCharCode(72, 69, 76, 76, 79);
                        document.getElementById("from-3").innerHTML = text1;
                    </script>