C-Sharp | Java | Python | Swift | GO | WPF | Ruby | Scala | F# | JavaScript | SQL | PHP | Angular | HTML
JavaScript String charAt() MethodThe JavaScript string charAt() method is used to find out a char value present at the specified index in a string. The index number starts from 0 and goes to n-1, where n is the length of the string. The index value can't be a negative, greater than or equal to the length of the string. SyntaxThe charAt() method is represented by the following syntax: String.charAt(index) Parameterindex - It represent the position of a character. ReturnsA char value JavaScript String charAt() Method ExampleLet's see some examples of charAt() method. Example 1Let's see a simple example to print a character. <script> var str="TheDeveloperBlog"; document.writeln(str.charAt(4)); </script> Output: t Example 2In this example, we will not pass an index value. <script> var str="TheDeveloperBlog"; document.writeln(str.charAt());//print first character </script> Output: J Example 3In this example, we will print the last character. <script> var str="TheDeveloperBlog"; document.writeln(str.charAt(str.length-1)); </script> Output: t
Next TopicJavaScript String
|