To reverse the order of elements in an array in TypeScript, you can use the reverse()
method. Here's an example:
index.ts117 chars4 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()
.
gistlibby LogSnag