In | Function to reverse arr [ ] from start to end ; Create a copy array and store reversed elements ; Now copy reversed elements back to arr [ ] ; Utility function to print an array ; Driver code
function revereseArray ( arr , n ) { let rev = new Array ( n ) ; for ( let i = 0 ; i < n ; i ++ ) rev [ n - i - 1 ] = arr [ i ] ; for ( let i = 0 ; i < n ; i ++ ) arr [ i ] = rev [ i ] ; } function printArray ( arr , size ) { for ( let i = 0 ; i < size ; i ++ ) document . write ( arr [ i ] + " " ) ; document . write ( " " ) ; } let arr = [ 1 , 2 , 3 , 4 , 5 , 6 ] ; let n = arr . length ; printArray ( arr , n ) ; revereseArray ( arr , n ) ; document . write ( " " ) ; printArray ( arr , n ) ;