Languages
[Edit]
EN

TypeScript - reverse array

0 points
Created by:
evangeline
420

In this article, we would like to show how to reverse an array in TypeScript.

Quick solution:

Note: be careful reversing array because reverse() method works on source array obcject. It is safe to call array.slice().reverse().

Safe reversion example

Edit

When we use array in another place of application it is safe to use source array copy.

Output:

Array map() method example

Edit

In 2009, ES5 introduced Array.prototype.map() method that lets us write quick reversion logic with an arrow function.

Output:

1
Donate to Dirask
Our content is created by volunteers - like Wikipedia. If you think, the things we do are good, donate us. Thanks!
Join to our subscribers to be up to date with content, news and offers.
Native Advertising
🚀
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

❤️💻 🙂

Join