How can I reverse an array in javascript without using libraries or string reverse or reverse

Follow the three simple step to I reverse an array in javascript without using libraries or string.reverse() or reverse()

 

First step:

Create an Array
var arr = [1,2,3,4]

Second step:

Create a function and pass created Array
function reverseArray(arr)
{

}

Third step:

Create a new Array in which, we Pust reverse Array and create for lool to reverse array

var reverse_arr = new Array;
for(var i = arr.length-1; i >= 0; i–)
{
reverse_arr.push(arr[i]);
}

Last step:

Call reverse function and print result on console
var temp = reverseArray(arr);

 

Final javaScript code-

 

var arr = [1,2,3,4]
var temp = reverseArray(arr);
function reverseArray(arr)
{
var reverse_arr = new Array;
for(var i = arr.length-1; i >= 0; i--)
{
reverse_arr.push(arr[i]);
}
console.log(reverse_arr);
}

 

Output-

4,3,2,1

 

You can use built-inĀ .reverse() method to reverse an array in javascript

var arr = [1,2,3,4]
var temp = arr.reverse();

 

Output-

4,3,2,1