💾arr.reversed()

JSobjectsArray methods ⟩ reversed()

💾 replit: array.reversed()

// 🔸 array.reversed()
// note: array.reverse() will reverse the array IN PLACE.
Array.prototype.reversed = function(){
    const [first, ...rest] = this;
    return first === undefined ? [] : [...rest.reversed(), first];
};

💈範例:

const a = [1,2,3,4];
a.reversed()       // [ 4, 3, 2, 1 ]

Last updated