JS Built-ins
StringString.prototype.atbeginner

String.prototype.at() β€” negative index

πŸ“– 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() β€” Negative Index

Negative indices count from the end: -1 is the last character, -2 is the second-to-last, etc.

Challenge: Implement lastChar(str) that returns the last character using .at(-1).

lastChar('hello') // β†’ 'o'
lastChar('abc')   // β†’ 'c'
πŸ’‘ Hints (1)
  • β€’ `.at(-1)` is equivalent to `str[str.length - 1]` but much cleaner.