Let's learn about the lodash method reverse, which reverses the order of an array.
_.revese(Array)
The
reverse() method of lodash is a useful method that
reverses the order of an array as its name suggests. For example, if you want to reverse the order of the array myNum below, you can simply use reverse().
let myNum = [1, 2, 3];
reverseNum = _.reverse(myNum);
The execution result of the code is as follows.
console.log(reverseNum);
// Result
[3, 2, 1]
I simply changed the order in reverse, as you can see.
! Using the JavaScript reverse() function., vanillaJS
By the way, it is also possible to use the built-in function reverse() in JavaScript. If we implement it in the same way, it would be like the following.
let myNum = [1, 2, 3];
reverseNum = myNum.reverse();
console.log(reverseNum);
// Result
[3, 2, 1]
As you can see from the results, it is the same as the reverse() above.
We have learned about the reverse() function in lodash up to this point.