Navigate back to the homepage

how to get first character of string in typescript?

Infinitbility
TypeScript
August 13th, 2022 · 1 min read
how to get first character of string in typescript?

Hi Friends 👋,

Welcome To Infinitbility! ❤️

To get first character of string in typescript, use substring() method to extracts first character from string. You have to only pass starting and ending postion of string so for first character pass 0, 1 as parameter it will return first character of string.

Let’s see short example to use substring() to get first character from string.

1text.substring(0, 1);

Today, I’m going to show you How do I get first character of string in typescript, as above mentioned, I’m going to use the above-mentioned substring() method.

Let’s start today’s tutorial how do you get first character of string in typescript?

Typescript get first character of string example using substring()

Here, we will take string variable with some data and use substring() method to get first char of string.

1let str: string = "Infinitbility";
2
3let char: string = str.substring(0, 1);
4console.log(char);
5
6// Output
7// 'I'

Typescript get first character of string example using index

Here, we will take string variable with some data and use index method to get first char of string.

1let str: string = "aGuideHub";
2
3let char: string = str[0];
4console.log(char);
5
6// Output
7// 'a'

Typescript get first character of string example using charAt()

Here, we will take string variable with some data and use charAt() method to get first char of string.

1let str: string = "SortoutCode";
2
3let char: string = str.charAt(0);;
4console.log(char);
5
6// Output
7// 'S'

I hope it helps you, All the best 👍.

Follow me on Twitter

Join our email list and get notified about new content

No worries, I respect your privacy and I will never abuse your email.

Every week, on Tuesday, you will receive a list of free tutorials I made during the week (I write one every day) and news on other training products I create.

Looking For React Native Tutorial?

we are trying to create the best Tutorial for react native developers.

When you want a daily updates about React Native Tutorial or infinitbility update subscribe to our newsletter.

Read React Native Tutorial

Request New Tutorial or Article on mail [email protected]

Guide book

Guidebook: The Javascript Monorepo Photoshop Guide

Tutorials

Categories

More articles from Infinitbility

how to get json array length in javascript?

how to get json array length in javascript?

An example of get length of json array in javascript with the step-by-step guide.

August 12th, 2022 · 1 min read
how to get value from json array in javascript?

how to get value from json array in javascript?

An example of get value from json array in javascript with the step-by-step guide.

August 12th, 2022 · 1 min read
© 2020–2022 Infinitbility
About
Link to $https://medium.com/infinitbilityLink to $https://www.facebook.com/InfinitbilityLink to $https://github.com/infinitbilityLink to $https://twitter.com/infinitbilityLink to $https://www.buymeacoffee.com/infinitbilityLink to $mailto:[email protected]