JS Coding Questions Logo
JS Coding Questions
#245💼 Interview💻 Code

How do you reverse an array

Advertisement

728x90

You can use the reverse() method to reverse the elements in an array. This method is useful to sort an array in descending order. Let's see the usage of reverse() method in an example,

javascript
1let numbers = [1, 2, 5, 3, 4];
2
3numbers.sort((a, b) => b - a);
4
5numbers.reverse();
6
7console.log(numbers); // [1, 2, 3, 4 ,5]

Advertisement

Responsive Ad
🎯 Practice NowRelated Challenge

JavaScript Coding Exercise 74

Test your knowledge with this interactive coding challenge.

Start Coding

Advertisement

728x90
245of476