JavaScript String method: charCodeAt()
[this page | pdf | back links]
The charCodeAt() method (when applied to a
JavaScript
string) returns
the Unicode character code of the character at specified index position (note:
strings in JavaScript are zero index based, so the first character is at
position zero).
It
has the following syntax with the following parameters:
string.charCodeAt(indexvalue)
Parameter
|
Required / Optional
|
Description
|
indexvalue
|
Required
|
Integer indicating
index (position) of character for which to return its Unicode character code
|
EXAMPLE:
HTML USED IN THIS EXAMPLE:
<!DOCTYPE html>
<html> <!-- Copyright (c) Nematrian Limited 2018 -->
<head>
<style>
table,th,tr,td {border: 1px solid black; border-collapse: collapse;}
</style>
</head>
<body>
<table>
<tr>
<th>Example</th>
<th>Resulting value of <code>x</code></th>
</tr>
<tr>
<td><code id="Example"></code></td>
<td><code id="Result"></code></td>
</tr>
</table>
<script>
var y = "abcde", pos=3;
document.getElementById("Example").innerHTML =
'var y = "' + y + '";<br>' +
'var x = y.charCodeAt(' + pos + ');';
document.getElementById("Result").innerHTML
= y.charCodeAt(pos);
</script>
</body>
</html>
|
FUNCTION THAT MAY ASSIST IN TESTING WHETHER FEATURE IS SUPPORTED:
function isSupportedJavaScriptMethodStringCharCodeAt() {
var z = "abc"; return !!z.charCodeAt;
} |
NAVIGATION LINKS
Contents | Prev | Next | JavaScript String Variables