Return the Unicode of the last character in a string - Javascript String

Javascript examples for String:charCodeAt

Description

Return the Unicode of the last 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 w  w.  ja v a 2 s .com
    var str = "HELLO WORLD";
    var n = str.charCodeAt(str.length-1);
    document.getElementById("demo").innerHTML = n;
}
</script>

</body>
</html>

Related Tutorials