TypeScript is a superset of JavaScript. This means that it is the parent of JavaScript. The cool thing about it is that it gives us the ability to do more compared to JavaScript. Moreover, wherever JavaScript runs, TypeScript runs as well.
The charAt()
method in TypeScript is used to return the character of a string at a specified index.
string.charAt(index)
index
: This is the index of the character we want to get. This is an integer value.
The value returned is a single character. If the character is not found, then nothing is returned.
export {}// create some strings.let name:string = "Theodore"let role:string = "Software Developer"let nickName:string = "Kcee"let hubby:string = "Coding"// get some characterslet char1 = name.charAt(2)let char2 = role.charAt(0)let char3 = nickName.charAt(5)let char4 = hubby.charAt(1)// print the charactersconsole.log(char1) // "e"console.log(char2) // "S"console.log(char3) // nothingconsole.log(char4) // "o"
let
keyword.charAt()
method, we get some characters from the strings we created.