Is there a way to use map() on an array in reverse order with javascript?
Not mutating the array at all, here is a one-liner O(n) solution I came up with:
myArray.map((val, index, array) => array[array.length - 1 - index]);
You can use Array.prototype.reduceRight()
var myArray = ["a", "b", "c", "d", "e"];
var res = myArray.reduceRight(function (arr, last, index, coll) {
console.log(last, index);
return (arr = arr.concat(last))
}, []);
console.log(res, myArray)
If you don't want to reverse the original array, you can make a shallow copy of it then map of the reversed array,
myArray.slice(0).reverse().map(function(...