Chrome Extension

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
Best JSON Validator, JSON Tree Viewer, JSON Beautifier at same place. Check how cool is the tool

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?
0 Comments