Reverse an Array in JavaScript Last Updated : 23 Jul, 2025 Comments Improve Suggest changes Like Article Like Report Try it on GfG Practice Here are the different methods to reverse an array in JavaScript1. Using the reverse() MethodJavaScript provides a built-in array method called reverse() that reverses the elements of the array in place. This method mutates the original array and returns the reversed array. JavaScript let a = [1, 2, 3, 4, 5]; a.reverse(); console.log(a); The reverse() method directly modifies the original array by reversing its elements.The reversed array is also returned as the result of the method2. Using For LoopAnother approach is to manually reverse an array by using a loop to swap elements. JavaScript const a = [1, 2, 3, 4, 5]; for (let i = 0; i < Math.floor(a.length / 2); i++) { let temp = a[i]; a[i] = a[a.length - 1 - i]; a[a.length - 1 - i] = temp; } console.log(a); A loop iterates through half the array, swapping the first element with the last, the second with the second-to-last, and so on.This approach directly modifies the original array without creating a new one.3. Using RecursionYou can use recursion by removing the first element of the array, reversing the rest of the array, and then pushing the removed element to the end of the reversed array. JavaScript const a = [1, 2, 3, 4, 5]; const reversed = (function reverse(a) { if (a.length === 0) { return []; } return [a.pop()].concat(reverse(a)); })([...a]); console.log(reversed); The recursive function removes the last element of the array using pop() and appends it to a new array.The original array remains unchanged by creating a copy using the spread operator.4. Using the reduce() MethodThe reduce() method can be used to accumulate the elements of the array in reverse order by pushing each element to the front of the accumulator. JavaScript let a = [1, 2, 3, 4, 5]; let revArr = a.reduce((acc, current) => [current, ...acc], []); console.log(revArr); The reduce() method iterates through the array, prepending each element to a new array.It does not affect the original array and constructs a reversed array as it processes elements.5. Using the Spread Operator and reverse()You can use the spread operator (...) to create a shallow copy of the array and then apply the reverse() method on that copy. JavaScript let a = [1, 2, 3, 4, 5]; let reversed = [...a].reverse(); console.log(reversed); The spread operator creates a shallow copy of the original array.The reverse() method is applied to the copied array, leaving the original array intact.6. Using a Stack (Last-In-First-Out Approach)A stack follows the Last-In-First-Out (LIFO) principle, which can be used to reverse an array by pushing elements to the stack and then popping them back out. JavaScript const a = [1, 2, 3, 4, 5]; const rev = []; while (a.length > 0) { rev.push(a.pop()); } console.log(rev); The pop() method removes elements from the original array one by one.These elements are pushed into a new array, effectively reversing their orde Reverse an array Visit Course Comment More infoAdvertise with us A amansingla Follow Improve Article Tags : JavaScript Web Technologies javascript-array JavaScript-DSA JavaScript-Questions +1 More Explore JavaScript Tutorial 8 min read JavaScript BasicsIntroduction to JavaScript 4 min read JavaScript Versions 2 min read How to Add JavaScript in HTML Document? 3 min read JavaScript Syntax 6 min read JavaScript Output 4 min read JavaScript Comments 2 min read JS Variables & DatatypesVariables and Datatypes in JavaScript 6 min read Global and Local variables in JavaScript 4 min read JavaScript Let 6 min read JavaScript const 5 min read JavaScript Var Statement 7 min read JS OperatorsJavaScript Operators 5 min read Operator precedence in JavaScript 2 min read JavaScript Arithmetic Operators 5 min read JavaScript Assignment Operators 5 min read JavaScript Comparison Operators 5 min read JavaScript Logical Operators 5 min read JavaScript Bitwise Operators 5 min read JavaScript Ternary Operator 4 min read JavaScript Comma Operator 2 min read JavaScript Unary Operators 4 min read JavaScript in and instanceof operators 3 min read JavaScript String Operators 3 min read JS StatementsJavaScript Statements 4 min read JavaScript if-else 3 min read JavaScript switch Statement 4 min read JavaScript Break Statement 2 min read JavaScript Continue Statement 1 min read JavaScript Return Statement 4 min read JS LoopsJavaScript Loops 3 min read JavaScript For Loop 4 min read JavaScript While Loop 3 min read JavaScript For In Loop 3 min read JavaScript for...of Loop 3 min read JavaScript do...while Loop 4 min read JS Perfomance & DebuggingJavaScript | Performance 4 min read Debugging in JavaScript 4 min read JavaScript Errors Throw and Try to Catch 2 min read JS ObjectObjects in Javascript 4 min read Object Oriented Programming in JavaScript 3 min read JavaScript Objects 6 min read Creating objects in JavaScript 5 min read JavaScript JSON Objects 3 min read JavaScript Object Reference 4 min read JS FunctionFunctions in JavaScript 4 min read How to write a function in JavaScript ? 4 min read JavaScript Function Call 2 min read Different ways of writing functions in JavaScript 3 min read Difference between Methods and Functions in JavaScript 3 min read Explain the Different Function States in JavaScript 3 min read JavaScript Function Complete Reference 3 min read JS ArrayJavaScript Arrays 7 min read JavaScript Array Methods 7 min read Best-Known JavaScript Array Methods 6 min read Important Array Methods of JavaScript 7 min read JavaScript Array Reference 4 min read Like