JavaScript charCodeAt()
The charCodeAt()
method is a JavaScript string method that returns the Unicode value of the character at a specified index within a string.
Syntax
The syntax for the charCodeAt()
method is:
str.charCodeAt(index)
str
: the string to extract a Unicode value from.index
: the position of the character within the string to return the Unicode value for.
Example
Here's an example of how to use the charCodeAt()
method:
const str = "Hello, World!";
const index = 0;
const unicodeValue = str.charCodeAt(index);
console.log(`The Unicode value of the character at index ${index} is ${unicodeValue}.`);
Output
The output of the code above would be:
The Unicode value of the character at index 0 is 72.