TypeScript String codePointAt() Method
The codePointAt() is an inbuilt TypeScript String method. It is mainly used to get the Unicode point value of any character that is given in a string.
Syntax:
stringName.codePointAt(position);
Parameters:
- position: Here you have to pass the index position of that character whose Unicode point value you want to retrieve.
Return Value:
It returns a Unicode value if the given index position of the character is valid, otherwise returns undefined.
Example 1: The below code is a basic implementation of the codePointAt() method in TypeScript.
Javascript
let str: string = "Hjëllo" ; let uniChar: number | undefined = str.codePointAt(1); console.log(uniChar); |
Output:
106
Example 2: The below code will show the behavior of the codePointAt() method if a invalid position passed to it.
Javascript
let str: string = "Hjëllo GFG" ; let uniChar: number | undefined = str.codePointAt(10); console.log(uniChar); |
Output:
undefined
Contact Us