InterviewHubPRO
Section Overview
Q249

Question 249 of 521

Part 4: Prototypes, Object Methods & Event Loop (174 - 253)

48%
JavaScript Internals (521 Qs)•Part 4: Prototypes, Object Methods & Event Loop (174 - 253)

How do you reverse an array

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
  let numbers = [1, 2, 5, 3, 4];
  numbers.sort((a, b) => b - a);
  numbers.reverse();
  console.log(numbers); // [1, 2, 3, 4 ,5]