javascript
Lodash - get the first element from an array
To get the very first item from an array using lodash, you can use its method head().
const arr = [10, 20, 30, 40, 50];
const first_item = _.head(arr);
// => 10
In the code snippet, we have defined an array arr and we want to get the very first element of this array. We have used lodash method head() for this purpose which is returning 10 as the result.
_.head() Lodash
_.head(Array)
Array: [Required] The array whose first element you want to get.
Example Demo
Was this helpful?
Similar Posts
- Lodash - Get index of first occurence of an array value
- Array.find() - get the very first element satisfy a condition Javascript
- Lodash - Get the last element of an array
- Remove first n elements from an array using 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
- Lodash - Get index of array item based on some condition