javascript

Lodash - Get the last element of an array

To get the last element from an array using lodash you can use its method _.last().

const items = [10, 20, 30, 40, 50];
const last_item = _.last(items);
// => 50

In the code snippet, we have an array named items that contain some values and we want to get the last value of this array. To get the last value from the array we are using the below syntax.

_.last(items)

_.last Lodash

_.last(Array)

The method takes Array parameter as required parameter .

Was this helpful?