Array toReversed in JavaScript

Level 3121 keystrokes

toReversed() returns a new array with elements in reverse order without mutating the original.

JavaScript code

// Create an array of letters
1const letters = ["a", "b", "c", "d"];
// toReversed() creates a new array in reverse order
2const reversed = letters.toReversed();
// Output the reversed array: ["d", "c", "b", "a"]
3console.log(reversed);
// Original array remains unchanged: ["a", "b", "c", "d"]
4console.log(letters);

Output

[ 'd', 'c', 'b', 'a' ]
[ 'a', 'b', 'c', 'd' ]
Practice typing this code

Practice typing this code. Results are not recorded in the rankings.

Symbols in this code

The symbols you type in this JavaScript code and how often they appear.

  • "× 8
  • ;× 4
  • ,× 3
  • .× 3
  • (× 3
  • )× 3
  • =× 2
  • [× 1
  • ]× 1

More JavaScript examples at level 3

← JavaScript typing practice