JavaScript String charCodeAt() MethodThe JavaScript string charCodeAt() method is used to find out the Unicode value of a character at the specific index in a string. The index number starts from 0 and goes to n-1, where n is the length of the string. It returns NaN if the given index number is either a negative number or it is greater than or equal to the length of the string. SyntaxThe charCodeAt() method is represented by the following syntax: Parameterindex - It represent the position of a character. ReturnA Unicode value JavaScript String charCodeAt() Method ExampleLet's see some simple examples of charCodeAt() method. Example 1Here, we will print the Unicode value of a character by passing its specific index. Test it NowOutput: 97 Example 2In this example, we will not pass any index number with the method. In such case, it will return the Unicode value of first character. Test it NowOutput: 74 Example 3Here, we will print the Unicode value of last character in a string. Test it NowOutput: 116 Example 4Here, we will provide the index number greater than the length of the string. In such case, the method returns NaN. Test it NowOutput: NaN Next TopicJavaScript String |
We provides tutorials and interview questions of all technology like java tutorial, android, java frameworks
G-13, 2nd Floor, Sec-3, Noida, UP, 201301, India