String charCodeAt() Method - Javascript String

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 Values

Parameter Description
index Required. A number representing the index of the character you want to return

Return Value:

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

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>

<button onclick="myFunction()">Test</button>

<p id="demo"></p>

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;


Related Tutorials