Search w3schools.com:

SHARE THIS PAGE

JavaScript charCodeAt() Method

String Object Reference JavaScript String Object

Example

Return the Unicode of the first character in a string:

var str = "HELLO WORLD";
var n = str.charCodeAt(0);

The result of n will be:


Try it yourself »


Definition and Usage

The charCodeAt() method returns the Unicode of the character at the specified index in a string.

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


Browser Support

Internet Explorer Firefox Opera Google Chrome Safari

The charCodeAt() method is supported in all major browsers.


Syntax

string.charCodeAt(index)

Parameter Values

Parameter Description
index Required. An integer representing the index of the character you want to return

Return Value

Type Description
Number The unicode of the character at the specified index

Technical Details

JavaScript Version: 1.2


More Examples

Example

Return the Unicode of the last character in a string:

var str = "HELLO WORLD";
var n = str.charCodeAt(str.length-1);

The result of n will be:


Try it yourself »


String Object Reference JavaScript String Object

Your suggestion:

Close [X]

Thank You For Helping Us!

Your message has been sent to W3Schools.

Close [X]