VOOZH about

URL: https://www.geeksforgeeks.org/typescript/typescript-array-reverse-method/

⇱ TypeScript Array reverse() Method - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

TypeScript Array reverse() Method

Last Updated : 4 Sep, 2024

The Array.reverse() method in TypeScript is used to reverse the elements of an array in place, modifying the original array. It rearranges the elements such that the first element becomes the last, the second element becomes the second-to-last, and so on.

Syntax:

array.reverse(); 

Parameter: This method does not accept any parameter. 

Return Value: This method returns the reversed single value of the array. 

The below examples illustrate the Array reverse() Method in TypeScript.

Example 1: In this example, we are reversing the order of elements in the arr array using the reverse() method.

Output:

[ 98, 7, 23, 89, 11 ]

Example 2: In this example the array is reversed twice using the reverse() method. First, [2, 5, 6, 3, 8, 9] becomes [9, 8, 3, 6, 5, 2], then it returns to the original order.

Output:

[ 2, 5, 6, 3, 8, 9 ]
Comment
Article Tags:
Article Tags:

Explore