Javascript Reference - JavaScript String charCodeAt() Method








charCodeAt() accepts zero-based position as its only parameter and returns the character's character code at the given position:

The index of the first character is 0, the second character 1, and so on.

Browser Support

charCodeAt() Yes Yes Yes Yes Yes

Syntax

stringObject.charCodeAt(index);

Parameter Values

Parameter Description
index Required. A integer based character index




Return Value

A number representing the unicode of the character at the specified index.

This method returns NaN if no character is at the specified index

Example


var stringValue = "hello world"; 
        
console.log(stringValue.charCodeAt(1)); //101

The code above generates the following result.