JavaScript: String.prototype.charAt
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.
console.log( "abc".charAt(0) === "a" ); // true
Note: "ð".length === 2
[see Character, Code Unit, Codepoint]
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