JS: String.prototype.at

By Xah Lee. Date: .

(new in JS: ECMAScript 2022)

str.at(index)
  • Return a string of length 1 that's the String Code Unit at index index of str.
  • Index can be negative, means count from right.
  • Out of bound index return undefined

🛑 WARNING: "😂".length === 2 〔see JS: String Code Unit

console.log("abcd".at(1) === "b");

console.log("abcd".at(-1) === "d");

// out of bound index return undefined
console.log("abcd".at(9) === undefined);

JavaScript. String, Char, Encoding, Hexadecimal

JS String.prototype