Home >>JavaScript String Methods >JavaScript String charCodeAt() Method
JavaScript charCodeAt() method is used to get the Unicode of the character at the specified index in a given input string. The index value starts from 0 and goes to n-1, where n is the total length of the given string.
Syntax:string.charCodeAt(index);
Parameter | Description |
---|---|
index | This is a required parameter. It defines a number representing the index of the character to return. |
Method | Chrome | Edge | Firefox | Safari | Opera |
---|---|---|---|---|---|
charCodeAt() | Yes | Yes | Yes | Yes | Yes |
<html> <body> <p>JERRY</p> <button onclick="myFunction()">Try it</button> <p id="demo"></p> <script> function myFunction() { var str = "JERRY"; var n = str.charCodeAt(0); document.getElementById("demo").innerHTML = n; } </script> </body> </html>
JERRY
<html> <body> <p>Jerry</p> <button onclick="myFunction()">Try it</button> <p id="demo"></p> <script> function myFunction() { var str = "Jerry"; var n = str.charCodeAt(str.length-1); document.getElementById("demo").innerHTML = n; } </script> </body> </html>
Jerry