JavaScript: Reverse an Array Elements

Amandeep Kochhar
1 min readOct 11, 2018

--

Today, lets see different methods of Reversing an Array Elements without using any third party libraries. All the ways of reversing an array is based on Pure JavaScript.

Using Array reverse() method

const a = [1,2,3,4,5,6,7,8,9];
const b = a.reverse();
console.log(b);

Using Array Indexes

const a = [1,2,3,4,5,6,7,8,9];
var b = [];
a.forEach((e,i) => b[a.length-(i+1)] = e);
console.log(b);

Using Array push() & pop() methods

const a = [1,2,3,4,5,6,7,8,9];
const b = [];
while (a.length > 0){
b.push(a.pop())
}
console.log(b);

If you any more Idea to perform this operation. Please mention in the comments. I will try to add mentioned methods. Leave a clap if it helped you in any way.

--

--

No responses yet