JavaScript charCodeAt () method
Examples
Returns Unicode encoded string of the first character:
var str = "HELLO WORLD";
var n = str.charCodeAt(0);
var n = str.charCodeAt(0);
n output:
try it"
Definition and Usage
Unicode encoding charCodeAt () method returns the position of the specified character.
Location string of the first character is 0, the second character position is 1, and so on.
Browser Support
All major browsers support charCodeAt () method
grammar
string.charCodeAt( index )
Parameter Value
参数 | 描述 |
---|---|
index | 必需。表示字符串中某个位置的数字,即字符在字符串中的下标。 |
return value
类型 | 描述 |
---|---|
Number | 返回在指定的位置的字符的 Unicode 编码。 |
technical details
JavaScript version: | 1.2 |
---|
More examples
Examples
Returns Unicode encoded string of the last character:
var str = "HELLO WORLD";
var n = str.charCodeAt(str.length-1);
var n = str.charCodeAt(str.length-1);
n output:
try it"