Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

reverse
lodash
array
communitycreator

How to use the reverse method in Lodash

Programming Bytes

Overview

The reverse method reverses an array. The changes will be made in the original array.

Syntax

_.reverse(array)

Arguments

This method takes the array to be reversed as an argument.

Return value

This method reverses the original array provided as an argument and returns it.

Code example

The below code demonstrates the use of the reverse method in Lodash:

Console
Using the reverse method

Code explanation

  • Line 6: We load the Lodash library file from the server link.

  • Line 8: We create an array arr with [1,2,3,4,5] as elements.

  • Line 11: We use the reverse method to reverse the array. This will reverse the order of the elements on the source array and returns it. Now the array is [5,4,3,2,1].

RELATED TAGS

reverse
lodash
array
communitycreator
RELATED COURSES

View all Courses

Keep Exploring