Parameters: This method accepts a single parameter.
- index: It is the index of the character in the string whose Unicode is to be used. The range of the index is from 0 to length – 1.
Return value: This method returns the Unicode (ranging between 0 and 65535) of the character whose index is provided to the method as the argument. If the index provided is out of range this method returns NaN
Below is an example of the String.prototype.charCodeAt() Method.
Example 1: This example shows the basic use of the String.prototype.charCodeAt() Method.
Example 2: In this example, the method charCodeAt() extracts the character from the string at index 4. Since this character is m, therefore this method returns the Unicode sequence as 109.
Example 3: In this example, the method charCodeAt() extracts the character from the string at index 20. Since the index is out of bounds for the string, therefore this method returns the answer as NaN.
- Chrome 1 and above
- Edge 12 and above
- Firefox 1 and above
- Internet Explorer 4 and above
- safari 1 and above
- Opera 4 and above
Please Login to comment...