String charAt() method
Learn about the charAt() string method. Which will return a new string consisting of the single character located base on it index.
Note: If no index is proved to
charAt()it will fallback to0
Using charAt() without index
const city = 'Miami';
console.log(city.charAt());
// charAt() using default index => 0
/**
* @return 'M'
*/
Using charAt() index
const country = 'USA';
country.charAt(1);
/**
* @return 'U'
*/
Using charAt() with a outbound index
// note: if the index pass to chartAt(999) is not in the string length
// this will return empty string
const country = 'USA';
country.charAt(999);
/**
* @return ""
*/
Top comments (0)