JavaScript Reverse Array | reverse() method | Example code

Use the reverse() method to reverse an array in JavaScript. This method reverses the order/sequence of the elements in an array. Note it will change the original array.

Syntax

Return value

Reversed elements array.

Example of JavaScript Reverse Array

Let’s see an example to reverse the sequence of elements of the array in js.

Output:

Example of JavaScript Reverse Array

How to reverse array without modifying in JavaScript?

You can Reverse array in JavaScript without mutating the original array use slice() to make a copy then reverse() it.

Reverse an array in JavaScript without reverse function

An array.pop() removes the popped element from the array, reducing its size by one. Once you’re at i === middle_element, your break condition no longer evaluates to true and the loop ends.

Do comment if you have any questions and suggestion on this tutorial.

Note: All JS Examples codes are tested on the Firefox browser and the Chrome browser.
OS: Windows 10
Code: HTML 5 Version


Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.