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?
Similar Posts
- Lodash - Get all elements of array except the last one
- Remove last n elements from an array using Lodash
- Efficiently Remove the Last Element from an Array in JavaScript [6 Methods Explained]
- Lodash - get the first element from an array
- Remove items starting from last untill given condition is false Lodash
- Get all values from an array which does not exist in other array Lodash
- Break an array into fixed length array groups using lodash in Javascript