JavaScript charAt method
The charAt method is used to obtain characters at the specified position from a string. The syntax is as follows:
The code copy is as follows:
str_object.charAt( x )
Parameter description:
| parameter | illustrate |
|---|---|
| str_object | String (object) to operate |
| x | Required. Number indicating the position |
Tip: The string is counted from 0.
charAt method example
The code copy is as follows:
<script language="JavaScript">
document.write( "jb51".charAt( 1 ) );
</script>
Run this example and output:
The code copy is as follows:
b
Tip: If the parameter x is not between 0 and the maximum length of the string, the method will return an empty string.