Array.reverse()

The Array.reverse() method is an extremely useful, yet simple JavaScript method that takes an array and reverses its contents.

Syntax

arr.reverse();

Reversing An Array

var arr = [1, 2, 3, 4, 5];

arr.reverse();
// returns [5, 4, 3, 2, 1]

If you're trying to reverse a string, you'll need to split it up into separate characters then join it back together in order to reverse the string itself.

var website = ['CodeSnippet'];

website.reverse();
// returns ['CodeSnippet'];

Try this the code snippet in your browser console.

If you'd like to take a closer look at how to reverse a string using JavaScript, checkout the Reverse a String blog post.


Shoot me an email at tim@timwheeler.com with any questions and if you enjoyed this, stay tuned and subscribe below! 👇