JavaScript Code

JavaScript String charAt()


String charAt()

str.charAt(n)
  • str is a string
  • n is an integer (position/index)

charAt() method returns the character from string str present at the index n.

Examples

1. get char at index

let name = 'apple';
let output = name.charAt(3);
console.log(output);
//output: l

2. n outside the range of string, charAt() returns empty string

let name = 'apple';
let output = name.charAt(15);
console.log(output);
//output: 

Copyright @2022