JavaScript tutorial:
charCodeAt method

 

Applies to: String Object

The charCodeAt method returns the Unicode encoding of the specified character.

Syntax

stringObj.charCodeAt(index)

The charCodeAt method syntax has these parts:

Part

Description

stringObj

Required. A String object or literal.

index

Required. The zero-based index of the specified character.

Return value

The charCodeAt method returns the Unicode encoding of the specified character.

Example

If there is no character at the specified index, NaN is returned.

The following example illustrates the use of the charCodeAt method:

function getCharCode(str,pos)
{
var s;
s = str.charCodeAt(pos - 1);
// Return Unicode character code.
return(s);
}
document.write(getCharCode("ABCDEFGHIJKLMNOPQRSTUVWXYZ","10"));

To run the code, paste it into JavaScript Editor, and click the Execute button.

See also: fromCharCode Method, String Object Methods

 

Home  |  About C-Point  |   Awards  |  Purchase  |  Contact Us
C Point
Antechinus® Creative Software: http://www.c-point.com
Net Marketing Insider: http://www.NetMarketingInsider.com
 
Copyright © 1998- C Point Pty Ltd. All Rights Reserved
Privacy Policy | Acceptable Use Policy (AUP)
 
71 Williamson Road, Para Hills 5096, Australia
Tel: +618 8263 3623 Fax: +618 8396 1477