To reverse an array in JavaScript, you can use the reverse() method, which is a built-in method available on the Array object. This method modifies the original array by reversing its elements in place. Here’s an example:

const array = [1, 2, 3, 4, 5];
array.reverse(); // Reverses the array in place
console.log(array); // Outputs [5, 4, 3, 2, 1]

In the example above, we first create an array containing the numbers 1 to 5. Then, we call the reverse() method on the array, which reverses its elements in place. Finally, we log the reversed array to the console.

It’s worth noting that the reverse() method modifies the original array and returns a reference to the same array, rather than creating a new array. If you want to create a new array that contains the reversed elements, you can use the spread operator (...) to create a new array that contains the reversed elements, like this:

const array = [1, 2, 3, 4, 5];
const reversedArray = [...array].reverse(); // Creates a new reversed array
console.log(array); // Outputs [1, 2, 3, 4, 5]
console.log(reversedArray); // Outputs [5, 4, 3, 2, 1]

In this example, we first create an array containing the numbers 1 to 5. Then, we use the spread operator (...) to create a new array that contains the same elements as the original array. We call the reverse() method on the new array to reverse its elements, and store the result in a new variable called reversedArray. Finally, we log both arrays to the console to confirm that the original array was not modified, and the new array contains the reversed elements.