JavaScript Code

How to reverse an array of strings?


Problem Statement

given an array of strings, 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