JavaScript .reverse()

codewithfan's avatar
Published Jun 21, 2021Updated Jun 1, 2023
Contribute to Docs

Reverses the order of the elements of an array in place and returns the reversed array.

  • Front-end engineers work closely with designers to make websites beautiful, functional, and fast.
    • Includes 34 Courses
    • With Professional Certification
    • Beginner Friendly.
      115 hours
  • Learn how to use JavaScript — a powerful and flexible programming language for adding website interactivity.
    • Beginner Friendly.
      15 hours

Syntax

The reverse() method does not take any parameters.

array.reverse();

Example

Reverse the elements in an array:

const numbers = [5, 2, 9];
numbers.reverse();
console.log(numbers);

This results in the following output:

[9, 2, 5]

Codebyte Example

The following example below uses .reverse() on an array, sports, to reverse the order of the elements.

Code
Output
Loading...

All contributors

Contribute to Docs

Learn JavaScript on Codecademy

  • Front-end engineers work closely with designers to make websites beautiful, functional, and fast.
    • Includes 34 Courses
    • With Professional Certification
    • Beginner Friendly.
      115 hours
  • Learn how to use JavaScript — a powerful and flexible programming language for adding website interactivity.
    • Beginner Friendly.
      15 hours