JavaScript: String.prototype.charAt

By Xah Lee. Date: . Last updated: .
str.charAt(index)
Return a string of length 1 that's the code unit (character) at index index of str. Return empty string if index is out of bound. Note, when the string contains NON-ASCII character, result may not be expected. [see Character, Code Unit, Codepoint]
console.log( "abc".charAt(0) === "a" ); // true
console.log( "😂".charAt(0) !== "😂" ); // true

console.log( "😂".charAt(0) === String.fromCharCode ( 0xd83d ) ); // true

// 😂
// name: FACE WITH TEARS OF JOY
// codepoint decimal: 128514
// codepoint hexadecimal: 1f602
// UTF8 encoding: F0 9F 98 82
// Utf16 encoding: D8 3D DE 02

If index is out of bound, return empty string.

console.log( "abc".charAt(9) === "" ); // true 
∑ JS in Depth
XAH  BUY NOW

JS in Depth

JS Obj Ref

DOM


JS Obj Ref

String

prototype