Description
The charAt() method returns the character at the specified index in a string.
The index of the first character is 0, and the index of the last character in a string called "txt", is txt.length-1.
This method has the form:
string.charAt(index)
Parameter | Description |
---|---|
index | (required) An integer between 0 and string.length-1 |
Examples
The following example shows the basic use of this method.
<script>
var s = "Hello from JavaScript";
document.write("First char: " + s.charAt(0));
document.write("<br />");
document.write("Last char: " + s.charAt(s.length-1));
</script>
This produces the following result:
Browser Support
Firefox | IE | Chrome | Opera | Safari |
---|---|---|---|---|