Hi Friends đź‘‹,

Welcome To Infinitbility! ❤️

To get the first letter of a string in javascript, use string[0] instead of string use your string variable name it will return the first character of string.

Today, I’m going to show you How do I get the first letter of a string in javascript, as mentioned above, I’m going to create a sample string variable then I will use the string index method to get the first letter of the string.

Let’s start today’s tutorial on how do you get the first letter of a string in javascript.

Javascript gets the first letter of the string

Here, we will do

  1. Create a sample string variable with data.
  2. Use string index to get the first character
// Create sample string variable with data.
let str = "infintbility";

// Use string index to get first character
console.log("First Char: ", str[0])

Output

I hope it helps you, All the best đź‘Ť.