Is there a way to use map() on an array in reverse order with javascript?

后端 未结 10 1042
离开以前
离开以前 2020-12-23 15:37

I want to use the map() function on a javascript array, but I would like it to operate in reverse order.

The reason is, I\'m rendering stacked React co

10条回答
  •  滥情空心
    2020-12-23 16:23

    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)

提交回复
热议问题