toReversed() method in JavaScript

The toReversed() method, introduced in ES2023, is a new addition to the Array.prototype object that allows you to create a new array containing the elements of the original array in reversed order. It's specifically designed to avoid modifying the original array, promoting immutability, and preventing unintended side effects in your code.

Functionality of toReversed() method

Benefits of JavaScript ES2023

In a nutshell, toReversed() provides a safe and efficient way to create reversed copies of arrays in ES2023, promoting a more functional and immutable coding style.

Example with Output

const originalArray = ['a', 'b', 'g', 'h', 'z'];
const reversedArray = originalArray.toReversed();

console.log(oroginalArray);
console.log(reversedArray);

Example with output