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.
charCodeAt() |
Yes | Yes | Yes | Yes | Yes |
stringObject.charCodeAt(index);
Parameter | Description |
---|---|
index | Required. A integer based character index |
A number representing the unicode of the character at the specified index.
This method returns NaN if no character is at the specified index
var stringValue = "hello world";
console.log(stringValue.charCodeAt(1)); //101
The code above generates the following result.