TypeScript | String charAt() Method

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:

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

filter_none

edit
close

play_arrow

link
brightness_4
code

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

chevron_right


Output:

o

Example 2: 

TypeScript

filter_none

edit
close

play_arrow

link
brightness_4
code

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

chevron_right


Output: 

str.charAt(0) is:J
str.charAt(1) is:a

full-stack-img

My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.


Article Tags :

Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.