# Vanilla JavaScript reverse an array

You will often want to reverse an array in JavaScript, imagine you're receiving data based on a date, but you want it to show it reversed in the frontend.

This is where the JavaScript reverse method comes in handy.
It's a super cool array method, and it's easy to use.

To reverse an array, we can call the reverse method on a variable.

```js
const array = ['a', 'b', 'c'];
array.reverse();
// [ 'c', 'b', 'a' ]
```

As you can see, this reversed our initial input array.

## JavaScript reverse array but keep original

You might not want to reverse the original array in some cases but want to create a copy.

This is where the [JavaScript spread operator](https://daily-dev-tips.com/posts/10-ways-to-use-the-spread-operator-in-javascript/) comes in handy.

```js
const array = ['a', 'b', 'c'];
const reverse = [...array].reverse();
// array: [ 'a', 'b', 'c' ]
// reverse: [ 'c', 'b', 'a' ]
```

And that's it, reversing arrays is pretty straightforward and comes in super handy.

You can have a play with today's code in the following Codepen.

%[https://codepen.io/rebelchris/pen/gOLaQPY]

### Thank you for reading, and let's connect!

Thank you for reading my blog. Feel free to subscribe to my email newsletter and connect on [Facebook](https://www.facebook.com/DailyDevTipsBlog) or [Twitter](https://twitter.com/DailyDevTips1)
