C-Sharp | Java | Python | Swift | GO | WPF | Ruby | Scala | F# | JavaScript | SQL | PHP | Angular | HTML
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: string.charCodeAt(index) 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. <script> var x="TheDeveloperBlog"; document.writeln(x.charCodeAt(3)); </script> Output: 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. <script> var x="TheDeveloperBlog"; document.writeln(x.charCodeAt());//It will return Unicode value of 'J' </script> Output: 74 Example 3Here, we will print the Unicode value of last character in a string. <script> var x="TheDeveloperBlog"; document.writeln(x.charCodeAt(x.length-1)); </script> Output: 116 Example 4Here, we will provide the index number greater than the length of the string. In such case, the method returns NaN. <script> var x="TheDeveloperBlog"; document.writeln(x.charCodeAt(12)); </script> Output: NaN
Next TopicJavaScript String
|