JS Built-ins
StringString.prototype.atbeginner

String.prototype.at() β€” second-to-last character

πŸ“– Usage Example
const str = 'Hello'
str.at(0)    // β†’ 'H'
str.at(-1)   // β†’ 'o'
str.at(1)    // β†’ 'e'

Use at() to access a character by index, supporting negative indices to count from the end.

String.prototype.at() β€” Index -2

str.at(-2) returns the second-to-last character.

Challenge: Implement secondToLast(str) using .at(-2).

secondToLast('hello') // β†’ 'l'
secondToLast('abc')   // β†’ 'b'
πŸ’‘ Hints (1)
  • β€’ `.at(-2)` counts 2 from the end.