charCodeAt()  String  instance method JS Home  <<  JS Reference  <<  String  <<  charCodeAt()

Description

Returns a numeric Unicode value of the character at the specified index.

Syntax

Signature Description
aString.charCodeAt(index)Returns a numeric Unicode value of the character at the specified index.

Parameters

Parameter Description
indexAn integer between 0 and the length of the string -1, up to 65,535.
  • Returns NaN if specified index is less than 0, or greater than 65,535 or the length of the string.
  • For values up to 65,536, values are represented by a pair of lower valued pseudo-characters whose usage comprises the character.
  • Visit the MDN network site for examples of how to extract these values.

Examples

The code below creates a string of the alphabet and returns a numeric Unicode value.


// Create alphabet string varible.
var theAlphabet = 'abcdefghijklmnopqrstuvwxyz';

// Return numeric Unicode value of the character at index 0.
alert(theAlphabet.charCodeAt(0));

Press the button below to action the above code:

Related Tutorials

JavaScript Basic Tutorials - Lesson 8 - Strings