TheDeveloperBlog.com

Home | Contact Us

C-Sharp | Java | Python | Swift | GO | WPF | Ruby | Scala | F# | JavaScript | SQL | PHP | Angular | HTML

JavaScript String charAt() Method

JavaScript string charAt() Method with example, by string literal, by string object (using new keyword), javascript string methods, charAt(index) method, concat(str) method, indexOf(str) method, lastIndexOf(str) method, lowerCase() method, upperCase() method, slice(beginIndex, endIndex) method, trim() method, toLowerCase(), slice(), concat(), charCodeAt() method etc.

<< Back to JAVASCRIPT

JavaScript String charAt() Method

The 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.

Syntax

The charAt() method is represented by the following syntax:

String.charAt(index)

Parameter

index - It represent the position of a character.

Returns

A char value

JavaScript String charAt() Method Example

Let's see some examples of charAt() method.

Example 1

Let's see a simple example to print a character.

<script>
var str="TheDeveloperBlog";
document.writeln(str.charAt(4));
</script>
Test it Now

Output:

t

Example 2

In this example, we will not pass an index value.

<script>
var str="TheDeveloperBlog";
document.writeln(str.charAt());//print first character
</script>
Test it Now

Output:

J

Example 3

In this example, we will print the last character.

<script>
var str="TheDeveloperBlog";
document.writeln(str.charAt(str.length-1));
</script>
Test it Now

Output:

t

Next TopicJavaScript String




Related Links:


Related Links

Adjectives Ado Ai Android Angular Antonyms Apache Articles Asp Autocad Automata Aws Azure Basic Binary Bitcoin Blockchain C Cassandra Change Coa Computer Control Cpp Create Creating C-Sharp Cyber Daa Data Dbms Deletion Devops Difference Discrete Es6 Ethical Examples Features Firebase Flutter Fs Git Go Hbase History Hive Hiveql How Html Idioms Insertion Installing Ios Java Joomla Js Kafka Kali Laravel Logical Machine Matlab Matrix Mongodb Mysql One Opencv Oracle Ordering Os Pandas Php Pig Pl Postgresql Powershell Prepositions Program Python React Ruby Scala Selecting Selenium Sentence Seo Sharepoint Software Spellings Spotting Spring Sql Sqlite Sqoop Svn Swift Synonyms Talend Testng Types Uml Unity Vbnet Verbal Webdriver What Wpf