JavaScript String codePointAt()

The codePointAt() method in JavaScript is used to return the Unicode code point value of the character at a specified index in a string. This method takes a single argument, which is the index of the character to return the code point value for. If the index is out of range, the codePointAt() method returns undefined.

Here is an example of how the codePointAt() method works:

const string1 = 'Hello, world!';

const result = string1.codePointAt(7);

// the result will be: 119

In the code example above, we first declare a string called string1 that contains the text Hello, world!. We then use the codePointAt() method to get the Unicode code point value of the character at index 7 in the string. The codePointAt() method takes a single argument, which is the index of the character to return the code point value for. In this case, we pass in the number 7 as the argument.

As a result of calling the codePointAt() method, the result variable will be set to 119, which is the Unicode code point value of the character at index 7 in the string1 string. If the index we were searching for was out of range (i.e., if we passed in a number greater than the length of the string), the result variable would be set to undefined.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

Blog at WordPress.com.

%d bloggers like this: