Example 1 — Reverse In Place
Call reverse() on a number array and log the mutated result.
const numbers = [1, 2, 3, 4, 5];
numbers.reverse();
console.log(numbers);
// [5, 4, 3, 2, 1] How It Works
- Start with five numbers. Indexes run
0…4. - Call reverse. Ends swap toward the middle:
1↔5,2↔4;3stays. - Same variable.
numbersnow holds[5, 4, 3, 2, 1]— length is unchanged. - No new array. This is mutation, not a copy.

