Reversing arrays

suggest change

Use toReversed() to create a reversed copy without modifying the source array:

const original = [11, 22, 33];
const reversed = original.toReversed();

console.log(reversed); // [33, 22, 11]
console.log(original); // [11, 22, 33]

reverse() performs the same reordering in place and returns the original array:

const values = [1, 2, 3, 4];
const sameArray = values.reverse();

console.log(values);            // [4, 3, 2, 1]
console.log(sameArray === values); // true

Both methods reverse only the selected array. They do not recursively reverse nested arrays; implement that behavior explicitly only when the data model requires it.

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents