73 of 264 menu

charCodeAt method

The charCodeAt method returns the character code (numerical value) at a specific position in a string. Character numbering starts from 0. If the specified number is greater than the last character of the string, then the method returns NaN.

Syntax

string.charCodeAt(character number in string);

Example

Let's output the code of the letter 'A' (character with the position 0):

let str = 'ABC'; let code = str.charCodeAt(0); console.log(code);

The code execution result:

65

Example

Let's look for a character whose number is not in a string:

let str = 'ABC'; let code = str.charCodeAt(4); console.log(code);

The code execution result:

NaN

See also

  • the String.fromCharCode method
    that performs the reverse operation
  • the charAt method
    that returns the character at the specified position in a string
English
AfrikaansAzərbaycanБългарскиবাংলাБеларускаяČeštinaDanskDeutschΕλληνικάEspañolEestiSuomiFrançaisहिन्दीMagyarՀայերենIndonesiaItaliano日本語ქართულიҚазақ한국어КыргызчаLietuviųLatviešuМакедонскиMelayuမြန်မာNederlandsNorskPolskiPortuguêsRomânăРусскийසිංහලSlovenčinaSlovenščinaShqipСрпскиSrpskiSvenskaKiswahiliТоҷикӣไทยTürkmenTürkçeЎзбекOʻzbekTiếng Việt
We use cookies for website operation, analytics, and personalization. Data processing is carried out in accordance with the Privacy Policy.
accept all customize decline