reverses the order of the elements in an array in typescript

To reverse the order of elements in an array in TypeScript, you can use the reverse() method. Here's an example:

index.ts
let arr: string[] = ["apple", "banana", "cherry"];
arr.reverse();
console.log(arr); // ["cherry", "banana", "apple"]
117 chars
4 lines

The reverse() method modifies the original array, reversing its order of elements. In the example above, the variable arr starts as ["apple", "banana", "cherry"], but after calling arr.reverse(), its value becomes ["cherry", "banana", "apple"]. Finally, we print the reversed array to the console using console.log().

related categories

gistlibby LogSnag