revision:
The toReversed() method of Array instances is the copying counterpart of the reverse() method. It returns a new array with the elements in reversed order.
toReversed()
Parameters: none
const uint8 = new Uint8Array([1, 2, 3]); const reversedUint8 = uint8.toReversed(); console.log(reversedUint8); // Uint8Array [3, 2, 1] console.log(uint8); // Uint8Array [1, 2, 3]
<div> <p id="reversed-1"></p> <p id="reversed-2"></p> <p id="reversed-3"></p> </div> <script> const items = [1, 2, 3]; console.log(items); // [1, 2, 3] document.getElementById("reversed-1").innerHTML = "array : " + items; const reversedItems = items.toReversed(); console.log(reversedItems); // [3, 2, 1] document.getElementById("reversed-2").innerHTML = "reversed array : " + reversedItems; console.log(items); // [1, 2, 3] document.getElementById("reversed-3").innerHTML = "array : " + items; </script>