CKTIS / JavaScript
Array.prototype.reverse: reversing in place
reverse reverses index order in place, preserves sparse holes, and returns the same object.
Version: ECMAScript 2026 draft; example target: Node.js 24.22.2
Syntax
array.reverse()array.reverse() swaps properties in pairs from the beginning and end using the receiver length, then returns that exact receiver. It mutates the array. For a sparse array it tests whether both properties exist: a hole is moved through the corresponding deletion rather than converted into an element whose value is undefined.
The method accepts no arguments and is generic for mutable array-like objects. Length zero or one needs no swap. A null or undefined receiver throws TypeError. A getter, setter, Proxy, non-writable property, or non-configurable indexed property can throw; earlier swaps need not be rolled back, so the receiver can remain partially reversed.
Examples
const values = [1, 2, 3];
const returned = values.reverse();
console.log(returned === values, values.join(","));
const sparse = [];
sparse.length = 4;
sparse[0] = "a";
sparse[2] = "c";
sparse.reverse();
console.log(sparse.length, Object.keys(sparse).join(","), sparse[1], sparse[3]);
const record = { 0: "x", 2: "z", length: 3 };
Array.prototype.reverse.call(record);
console.log(record[0], record[2], record.length === 3);Result
true 3,2,1 4 1,3 c a z x true