Last updated 2 years ago
JS ⟩ objects ⟩ Array ⟩ 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 ]
Array.prototype.reverse()
str.reverse()
recursion