String.prototype.charCodeAt() Method in String Class of Javascript Syntax with Examples
2796 Views
Usage
charCodeAt(int index) return the unicode value of the character in specified index of the string.
Syntax
String.charCodeAt(int index);
index - specify which position character needs to take from the string. index is starting from zero.
Example
var userName = "kumar";
//Returns chartacter unicode value at 2 index which means `109`.
var char1 = userName.charCodeAt(2);
document.write("character unicode value is "+char1+" at 2.");
//No characters unicode value at 54 index So returns empty character
var char2 = userName.charCodeAt(54);
document.write("character unicode value is "+char2+" at 54.");
Output
character unicode value is 109 at 2.
character unicode value is at 54.