Example 1 — Basic Reverse Copy
Flip a number array and keep the original intact.
const numbers = [1, 2, 3, 4, 5];
const flipped = numbers.toReversed();
console.log(flipped);
console.log(numbers); How It Works
- Start with five numbers. Order is
1…5. - Call toReversed(). Builds a new array with ends swapped.
- flipped is reversed. You get
[5, 4, 3, 2, 1]. - Original stays.
numbersis still[1, 2, 3, 4, 5].

