# How to reverse a JavaScript array

> Learn how to reverse a JavaScript array with the reverse() method, and how to keep the original intact by first copying it with the spread operator or slice.

Author: [Flavio Copes](https://flaviocopes.com/about/) | Published: 2020-06-20 | Topics: [JavaScript](https://flaviocopes.com/tags/js/) | Canonical: https://flaviocopes.com/how-to-reverse-array-javascript/

I had the need to reverse a [JavaScript](https://flaviocopes.com/javascript/) array, and here is what I did.

Given an array `list`:

```js
const list = [1, 2, 3, 4, 5]
```

The easiest and most intuitive way is to call the `reverse()` method of an array.

This method alters the original array, so I can declare `list` as a const, because I don't need to reassign the result of calling `list.reverse()` to it:

```js
const list = [1, 2, 3, 4, 5]
list.reverse()

//list is [ 5, 4, 3, 2, 1 ]
```

You can pair this method with the spread operator to first copy the original array, and then reversing it, so the original array is left untouched:

```js
const list = [1, 2, 3, 4, 5]
const reversedList = [...list].reverse()

//list is [ 1, 2, 3, 4, 5 ]
//reversedList is [ 5, 4, 3, 2, 1 ]
```

Another way is to use `slice()` without passing arguments:

```js
const list = [1, 2, 3, 4, 5]
const reversedList = list.slice().reverse()

//list is [ 1, 2, 3, 4, 5 ]
//reversedList is [ 5, 4, 3, 2, 1 ]
```

but I find the spread operator more intuitive than `slice()`.
