JavaScript - Use map() on an Array in Reverse Order Last Updated : 24 Jan, 2025 Comments Improve Suggest changes Like Article Like Report Here are the different methods to use map() on an array in reverse order with JavaScript1. Using JavaScript array.reverse() methodThe idea is to use the .reverse() method just after applying the .slice() method. Then use the .map() method on the reversed array to perform the task. JavaScript let a = [1, 3, 5, 7]; function gfg_Run() { let new = a.slice(0).reverse().map( function (val, index) { return val * 2; } ); console.log(new) } gfg_Run(); Output[ 20, 18, 14, 10, 6, 2 ]In this exampleThe code first creates a reversed copy of array a using slice(0).reverse() and then applies map() to multiply each element by 2.The transformed array is logged, where the elements of a are reversed and doubled.2. Using index parameter of JavaScript array.map() methodThe Javascript map() method in JavaScript creates an array by calling a specific function on each element present in the parent array. JavaScript let a = [8, 5, 15, 70, 9]; function gfg_Run() { let newArr = a.map( (val, index, array) => 1 / 2 * array[array.length - 1 - index] ); console.log(newArr); } gfg_Run(); Output[ 4.5, 35, 7.5, 2.5, 4 ] In this exampleThe map() function processes each element by accessing the corresponding element from the array in reverse order (arr[arr.length - 1 - index]) and multiplying it by 1/2.The transformed array contains elements from the original array in reverse order, halved.3. Using JavaScript loop in reverse orderIterate over an array in reverse order using a for loop, starting from the last index and decrementing to zero. JavaScript let a = [8, 5, 15, 70, 9]; let rev= []; for (let i = a.length - 1; i >= 0; i--) { rev.push(a[i] * 2); } console.log(rev); Output[ 20, 18, 140, 30, 10, 16 ]In this exampleThe for loop iterates through array a in reverse order, multiplying each element by 2 and pushing the result into the rev array.The rev array contains the elements of a in reverse order, each doubled.4. Using reduceRight()The reduceRight() method processes the array from the last element to the first, making it a natural fit for reverse mapping. JavaScript let num = [1, 2, 3, 4, 5]; let rev = num.reduceRight((acc, num) => { acc.push(num * 2); return acc; }, []); console.log(rev); Output[ 10, 8, 6, 4, 2 ] In this examplereduceRight() iterates over the array in reverse order.For each element, the transformation is applied (num * 2), and the result is pushed into the accumulator array (acc).5. Using forEach() as an AlternativeIf you want to avoid using map() entirely, you can achieve a similar result using forEach() while iterating in reverse order. JavaScript let num = [1, 2, 3, 4, 5]; let rev = []; num.forEach((num, i, arr) => { rev.unshift(num * 2); }); console.log(rev); In this exampleThe forEach() method processes the array in its original order, but unshift() is used to prepend the transformed elements, effectively reversing the result. Comment More infoAdvertise with us P PranchalKatiyar Follow Improve Article Tags : JavaScript Web Technologies javascript-array JavaScript-DSA JavaScript-Misc +1 More Similar Reads How to serialize a Map in JavaScript ? In this article, we will discuss, the serialization of maps in JavaScript. Serialization is the conversion of an object or a data structure to another format that is easily transferrable on the network. In JavaScript, the format suitable for transferring is JSON string. So, we usually call the JSON. 2 min read How to iterate over Map elements in JavaScript ? Map() is very useful in JavaScript it organises elements into key-value pairs. This method iterates over each element in an array and applies a callback function to it, allowing for modifications before returning the updated array." The Map() keyword is used to generate the object. The map() method 3 min read How are elements ordered in a Map in JavaScript ? In JavaScript, a new object called Map was introduced in the ES6 version. A map is a collection of elements where each element is stored in a key, value pair. Map objects can store both objects as well as primitive data types. The elements of a map are iterable. Elements are always iterated in the i 2 min read What is JavaScript Map and how to use it ? What is Map?A Map in JavaScript is a collection of key-value pairs where keys can be any data type. Unlike objects, keys in a Map maintain insertion order. It provides methods to set, get, delete, and iterate over elements efficiently, making it useful for data storage and retrieval tasks.Syntaxnew 2 min read How to Sort a Map in JavaScript? Sorting a Map in JavaScript involves ordering its key-value pairs based on the keys or values. Since Maps maintain the insertion order, you can't directly sort them like arrays. Instead, you'll need to convert the Map into an array, sort it, and then convert it back into a Map.Below are the approach 3 min read How to map array values without using map method in JavaScript ? Array elements can be mapped by using looping methods in JavaScript. The map() method creates a new array with the results of the output of a function called for each array element. This can also be implemented using a for loop in JavaScript.Approach 1: For this, we can create two arrays, in which o 3 min read What is the difference between Map and WeakMap in JavaScript ? In this article, we will talk about the difference between Map and WeakMap which are introduced by ES6. Javascript object supports only one key object. For supporting multiple key objects, Then Map comes on this path. Map: A Map is an unordered list of key-value pairs where the key and the value can 4 min read How To Convert Map Keys to an Array in JavaScript? Here are the various methods to convert Map keys to an array in JavaScript1. Using array.from() MethodThe Array.from() method in JavaScript converts Map keys to an array by using 'Array.from(map.keys())'. JavaScriptlet map = new Map().set('GFG', 1).set('Geeks', 2); let a = Array.from(map.keys()); co 2 min read How to convert a plain object into ES6 Map using JavaScript ? The task is to convert a JavaScript Object into a plain ES6 Map using JavaScript. we're going to discuss a few techniques. To understand the difference between a map and an object please go through the Map vs Object in JavaScript article. Below are the following approaches to converting a plain obje 2 min read JavaScript - Use map() on an Array in Reverse Order Here are the different methods to use map() on an array in reverse order with JavaScript1. Using JavaScript array.reverse() methodThe idea is to use the .reverse() method just after applying the .slice() method. Then use the .map() method on the reversed array to perform the task.JavaScriptlet a = [ 3 min read Like