JavaScript Code


How to reverse an array of strings in JavaScript?


Reverse an array of strings in JavaScript

In this tutorial, you are given an array of strings. You should write a JavaScript program to reverse the order of elements in the array, or just reverse the array.

Solution

To reverse an array, use array method reverse(). reverse() method reverses the calling array in-place.

Program

names is the given array of strings. We use reverse() method to reverse names array.

let names = ['Anita', 'Amy', 'America', 'Alba'];
names.reverse();
console.log(names);



copyright @2022