Javascript examples for String:charCodeAt
The charCodeAt() method returns the Unicode of the character at the specified index in a string.
The index starts at 0.
Parameter | Description |
---|---|
index | Required. A number representing the index of the character you want to return |
A Number, representing the unicode of the character at the specified index.
The following code shows how to return the Unicode of the first character in a string
<!DOCTYPE html> <html> <body> <button onclick="myFunction()">Test</button> <p id="demo"></p> <script> function myFunction() {/* w ww.j ava 2s.c om*/ var str = "HELLO WORLD"; var n = str.charCodeAt(str.length-1); document.getElementById("demo").innerHTML = n; } </script> </body> </html>