All of these answers will mutate the array, which is not what it wants to do, unless you want to add another .reverse () after each run.
But since oyu uses loDash, you can easily avoid this by wrapping the array inside a clone or cloneDeep in each () call
var letterArray = [ 'a', 'b', 'c', 'd', 'e' ]; _.each( _.clone(letterArray).reverse(), function(v, i) { console.log( i+1 ); });
this will write 5, 4, 3, 2, 1 without affecting the original array.
sean6bucks
source share