character = str.charAt(index)
Arguments: The only argument to this function is the index in the string from where the single character is to be extracted.
- index: The range of this index is between 0 and length – 1. If no index is specified then the first character of the string is returned as 0 is the default index used for this function.
Return Value: Returns a single character located at the index specified as the argument to the function. If the index is out of range, then this function returns an empty string.
Below is an example of the String charAt() Method.
Example 2: In this example, the function charAt() finds the character at index 9 and returns it.
Example 3: In this example, the function charAt() finds the character at index 50. Since the index is out of bounds for the given string therefore the function returns “”an empty string.
- Chrome 1 and above
- Edge 12 and above
- Firefox 1 and above
- Internet Explorer 3 and above
- Opera 3 and above
- Safari 1