String charCodeAt() Method - Javascript String

Javascript examples for String:charCodeAt

Description

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>
<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>

Related Tutorials