Imagine you're receiving data based on a date, for example. In the frontend, you'll most likely want to show the data reversed, meaning the most recent date first.
It's a super cool array method, and it's easy to use.
const array = ['a', 'b', 'c']; array.reverse(); // [ 'c', 'b', 'a' ]
As you can see, the method reversed our initial input array.
You might not want to reverse the original array in some cases but want to create a copy.
const array = ['a', 'b', 'c']; const reverse = [...array].reverse(); // array: [ 'a', 'b', 'c' ] // reverse: [ 'c', 'b', 'a' ]
Reversing arrays is pretty straightforward and comes in super handy.
See the example code in this Codepen
You can have a play with today's code here:
Thank you for reading, and let's connect!
Thank you for reading my blog. Feel free to subscribe to my email newsletter and connect on Facebook or Twitter