JavaScript's String.prototype.charAt()
May 5, 2021
This is just an object’s method that returns a single UTF-16 code unit to the specified offset of the string.
Code view
- const text = ‘I love my country!’;
- const find = 5;
- console.log(`The character at index ${find} is ${text.chart(find)}`);
// expected output: “The character at index 5 is e”
Syntax
charAt(index)
Parameters
index
An integer between 0 and 1-less-than the length of the string.
Description
From left to right. The index starts the first character is 0. This string is stringName.length-1, If the starts you supply is out of the range, JavaScript returns an empty string.