Access Character in String using []
str[n]
str
is a string[]
is square bracket notationn
is index
str[n] returns the character from the string str
present at the index n
.
Examples
1. character in string at index
let name = 'apple';
let output = name[3];
console.log(output);
2. n
is out of the range for given string length. str[n] returns undefined
.
let name = 'apple';
let output = name[15];
console.log(output);