JS Built-ins
← Array189 / 226
ArrayArray.prototype.toReversedintermediate

Array.prototype.toReversed() β€” reverse string array

πŸ“– Usage Example
const words = ['alpha', 'beta', 'gamma']
words.toReversed()  // β†’ ['gamma', 'beta', 'alpha']

Use toReversed() on string arrays to produce a reversed copy for display or comparison.

Array.prototype.toReversed() β€” any element type

toReversed() works on arrays of any element type β€” numbers, strings, objects, etc.

Challenge: Implement reverseStringArray(arr) that returns arr.toReversed() for a string array.

reverseStringArray(['a', 'b', 'c']) // β†’ ['c', 'b', 'a']
reverseStringArray(['hello', 'world']) // β†’ ['world', 'hello']
πŸ’‘ Hints (2)
  • β€’ `toReversed()` is generic β€” it works the same way regardless of element type.
  • β€’ The returned array is always a new object, even for string arrays.