JavaScript charCodeAt method
The charCodeAt method is used to obtain Unicode encoding of characters with specified positions from a string. The syntax is as follows:
The code copy is as follows:
str_object.charCodeAt( x )
Parameter description:
| parameter | illustrate |
|---|---|
| str_object | String (object) to operate |
| x | Required. Number indicating the position |
Tip: The string is counted from 0.
charCodeAt method example
The code copy is as follows:
<script language="JavaScript">
document.write( "jb51".charCodeAt( 1 ) );
</script>
Run this example and output:
The code copy is as follows:
98
If the parameter x is not between 0 and the maximum length of the string, the method returns NaN.
The charCodeAt method is very similar to the charAt method, except that the former returns the encoding of characters at the specified position, while the latter returns a substring of characters.