-
Notifications
You must be signed in to change notification settings - Fork 2
JS String Prototype CharCodeAt
The charCodeAt()
method returns the numeric Unicode value of the character at the given index (except for unicode codepoints > 0x10000).
str.charCodeAt(index)
index
An integer greater than or equal to 0 and less than the length of the string; if it is not a number, it defaults to 0.
Note that charCodeAt()
will always return a value that is less than 65536. This is because the higher code points are represented by a pair of (lower valued) "surrogate" pseudo-characters which are used to comprise the real character. Because of this, in order to examine or reproduce the full character for individual characters of value 65536 and above, for such characters, it is necessary to retrieve not only charCodeAt(i)
, but also charCodeAt(i+1)
(as if examining/reproducing a string with two letters). See example 2 and 3 below.
charCodeAt()
returns NaN
if the given index
is less than 0 or is equal to or greater than the length of the string.
'ABC'.charCodeAt(0); // returns 65
var str = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
document.write(str.charCodeAt(str.length - 1));
// Output: 90
Learn to code and help nonprofits. Join our open source community in 15 seconds at http://freecodecamp.com
Follow our Medium blog
Follow Quincy on Quora
Follow us on Twitter
Like us on Facebook
And be sure to click the "Star" button in the upper right of this page.
New to Free Code Camp?
JS Concepts
JS Language Reference
- arguments
- Array.prototype.filter
- Array.prototype.indexOf
- Array.prototype.map
- Array.prototype.pop
- Array.prototype.push
- Array.prototype.shift
- Array.prototype.slice
- Array.prototype.some
- Array.prototype.toString
- Boolean
- for loop
- for..in loop
- for..of loop
- String.prototype.split
- String.prototype.toLowerCase
- String.prototype.toUpperCase
- undefined
Other Links