Open In App

TypeScript String codePointAt() Method

Last Updated : 22 Jul, 2024
Comments
Improve
Suggest changes
Like Article
Like
Report

The codePointAt() method is a built-in TypeScript string method. It is primarily used to retrieve the Unicode code point value of a character at a specified position within a string.

Syntax:

stringName.codePointAt(position);

Parameters:

  • position: This parameter requires the index position of the character whose Unicode code 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.

Examples of codePointAt() Method

Example 1: Basic Implementation of the codePointAt() Method

The following code demonstrates 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: Handling Invalid Position

The following code shows the behavior of the codePointAt() method when an invalid position is passed to it.

JavaScript
let str: string = "Hjëllo GFG";
let uniChar: number|undefined = str.codePointAt(10);
console.log(uniChar);

Output:

undefined

Next Article

Similar Reads