Get the letter at specific position in a string JavaScript

How to get letter at specific position in a string JavaScript

Posted by Ervin Adams on August 28, 2022

Get the letter at specific position in a string JavaScript

How to get letter at specific position in a string JavaScript

Posted by Ervin Adams on August 28, 2022

Here is how you can get a character at specific position in a string: 

Use charAt()

const str = 'Happy coding';

console.log(str.charAt(4)); //y
console.log(str.charAt(7)); //o

Use bracket notations

const str = 'Happy coding';

console.log(str[4]); //y
console.log(str[7]); //o

 

Any question?
This field is required
Your question have been successfully submitted and will be reviewed before published
Please login to ask a question