JS Built-ins
StringString.prototype.atbeginner

String.prototype.at() β€” positive 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()

String.prototype.at(index) returns the character at the given index. For non-negative indices it behaves like bracket notation, but it also accepts negative indices.

Challenge: Implement getChar(str, i) that returns the character at index i using .at().

getChar('hello', 0) // β†’ 'h'
getChar('hello', 1) // β†’ 'e'
πŸ’‘ Hints (1)
  • β€’ `str.at(0)` is equivalent to `str[0]` for non-negative indices.