Skip to content
Related Articles

Related Articles

Improve Article
Save Article
Like Article

TypeScript | String charAt() Method

  • Last Updated : 09 Aug, 2021

The charAt() method in TypeScript is used to return the character at the specified index of the string. The characters string are indexed from left to right.

Syntax:

Hey geek! The constant emerging technologies in the world of web development always keeps the excitement for this subject through the roof. But before you tackle the big projects, we suggest you start by learning the basics. Kickstart your web development journey by learning JS concepts with our JavaScript Course. Now at it's lowest price ever!

string.charAt( index )

Parameter: This method accepts a single parameter as mentioned above and described below:

  • index: It is an integer value between 0 and 1 less than the length of the string.

Return Value: This method returns a character for the given index in the argument.



Below examples illustrate the working of charAt() method in TypeScript:
Example 1: 

TypeScript




// Original string
var str = new String(
    'JavaScript is object oriented language');
 
// Finding the character at given index 
var value = str.charAt(14);
console.log(value);

Output:

o

Example 2: 

TypeScript




// Original string
var str = new String(
    'JavaScript is object oriented language');
 
// Finding the character at given index 
console.log("str.charAt(0) is: " + str.charAt(0));
console.log("str.charAt(1) is: " + str.charAt(1)); 

Output: 

str.charAt(0) is:J
str.charAt(1) is:a
My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!