The method ‘toReversed()’ is added to JavaScript in ECMAScript 2023 (ES 13) version. The advantage of this method over ‘reverse()’ is that it doesn’t change the original array. It reverses the array and returns a new array.
Below is the example code for it and the output:
x=[1,2,3,4,5];
x.reverse();
console.log('The reverse method applied and the original array printed', x);
y=[6,7,8,9,10];
z=y.toReversed(); //assigning the returned array
console.log('The toReversed method applied and the original array printed',y);
console.log('The assigned array:', z);
