Horje
JavaScript Array toReversed() Method

The toReversed() method in Javascript arrays returns a new array with the elements in reversed order and the original array remains unaffected. The toReversed() method, introduced in ECMAScript 2023, offers a way to reverse the order of elements in an array.

Unlike the sort() method, it creates a new array with the elements arranged in reverse order. This method preserves the original array, ensuring it remains unmodified.

Syntax:

It will not take any parameter and return the array with elements in reverse order.

let result_array = actual_array.toReversed()

Example: JavaScript program to reverse the elements in an array

JavaScript
let actual_array = [60, 78, 90, 34, 67];
console.log("Existing Array: ", actual_array);

let result_array = actual_array
    .toReversed();
console.log("Final Array: ", result_array);

Output:

Existing Array: [60, 78, 90, 34, 67]
Final Array:  [67, 34, 90, 78, 60]



Reffered: https://www.geeksforgeeks.org


JavaScript

Related
What is the Infinity Global Property in JavaScript ? What is the Infinity Global Property in JavaScript ?
JavaScript Array with() Method JavaScript Array with() Method
How to Filter an Array in JavaScript ? How to Filter an Array in JavaScript ?
JavaScript Program for nth Term of Geometric Progression JavaScript Program for nth Term of Geometric Progression
How to Convert String to Array of Objects JavaScript ? How to Convert String to Array of Objects JavaScript ?

Type:
Geek
Category:
Coding
Sub Category:
Tutorial
Uploaded by:
Admin
Views:
14