Skip to content
geeksforgeeks
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • Tutorials
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
  • Practice
    • Build your AI Agent
    • GfG 160
    • Problem of the Day
    • Practice Coding Problems
    • GfG SDE Sheet
  • Contests
    • Accenture Hackathon (Ending Soon!)
    • GfG Weekly [Rated Contest]
    • Job-A-Thon Hiring Challenge
    • All Contests and Events
  • TypeScript Tutorial
  • TS Exercise
  • TS Interview Questions
  • TS Cheat Sheet
  • TS Array
  • TS String
  • TS Object
  • TS Operators
  • TS Projects
  • TS Union Types
  • TS Function
  • TS Class
  • TS Generic
Open In App
Next Article:
TypeScript String String.fromCodePoint() Method
Next article icon

TypeScript String charAt() Method

Last Updated : 19 Jul, 2024
Comments
Improve
Suggest changes
Like Article
Like
Report

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

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:

Examples of TypeScript String charAt() Method

Example 1: Basic Usage of charAt()

In this example, we will use the charAt() method to get the character at a specific index in a string.

TypeScript
const str: string = "Hello, World!"; const charAtIndex: string = str.charAt(4);  console.log(charAtIndex); 

Output:

o

Example 2: Iterating Over a String Using charAt()

In this example, we will demonstrate how to use charAt() in a loop to access and print each character of a string.

TypeScript
const str: string = "JavaScript"; for (let i = 0; i < str.length; i++) {     console.log(`str.charAt(${i}) is: ${str.charAt(i)}`); } 

Output: 

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


Next Article
TypeScript String String.fromCodePoint() Method

S

SHUBHAMSINGH10
Improve
Article Tags :
  • JavaScript
  • TypeScript
  • Web Technologies

Similar Reads

  • TypeScript String charCodeAt() Method
    The String.charCodeAt() method in TypeScript returns the Unicode value of the character at a specified index in a string. It takes an integer index as a parameter and returns the corresponding Unicode value as a number. Syntaxstring.charCodeAt(index);Parameter: This method accepts a single parameter
    2 min read
  • TypeScript String.fromCharCode() Method
    The fromCharCode() is an inbuilt TypeScript String method. It mainly changes Unicode code points within the Basic Multilingual Plane (BMP) into strings. Although it provides a method for dealing with characters through typing on a keyboard it has restrictions when it comes to characters, outside the
    1 min read
  • TypeScript String codePointAt() Method
    The codePointAt() method is a built-in TypeScript string method. It is primarily used to retrieve the Unicode code point value of a character at a specified position within a string. Syntax:stringName.codePointAt(position);Parameters:position: This parameter requires the index position of the charac
    2 min read
  • TypeScript String String.fromCodePoint() Method
    The fromCodePoint() is an inbuilt TypeScript String method. It is mainly used to get the string value of any given Unicode point value. This method is really helpful when you want to handle characters that are not readily available through keyboard input. Syntax:String.fromCodePoint(...codePoints: n
    1 min read
  • TypeScript String
    In TypeScript, the string is sequence of char values and also considered as an object. It is a type of primitive data type that is used to store text data. The string values are used between single quotation marks or double quotation marks, and also array of characters works same as a string. TypeSc
    4 min read
  • JavaScript String charAt() Method
    The JavaScript String charAt() method retrieves the character at a specified index in a string. The index is passed as an argument to the method, and it returns the character at that position. Note: JavaScript uses zero-based indexing, meaning the first character is at index 0, the second at index 1
    3 min read
  • JavaScript String. toWellFormed() Method
    One very common job in the world of JavaScript is working with strings, and sometimes it's really important to ensure that those strings are well-formed. The toWellFormed method is rather one of the new ones in JavaScript. It was added to help developers work with strings containing Unicode characte
    2 min read
  • JavaScript String charCodeAt() Method
    The JavaScript str.charCodeAt() method returns a Unicode character set code unit of the character present at the index in the string specified as the argument. The index number ranges from 0 to n-1, where n is the string's length. Syntax:str.charCodeAt(index)Parameters: This method accepts a single
    3 min read
  • JavaScript String Methods
    JavaScript strings are the sequence of characters. They are treated as Primitive data types. In JavaScript, strings are automatically converted to string objects when using string methods on them. This process is called auto-boxing. The following are methods that we can call on strings. slice() extr
    12 min read
  • JavaScript String fromCharCode() Method
    The fromCharCode() method in JavaScript is a static method of the String object. Which is used to create a string from a sequence of Unicode values. Syntax:String.fromCharCode(n1, n2, ..., nX)Parameters:The method takes the UTF-16 Unicode sequences as its argument. The number of arguments to this me
    3 min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences