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
Best JSON Validator, JSON Tree Viewer, JSON Beautifier at same place. Check how cool is the tool
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.
Array: [Required] The array whose first element you want to get.
Search Index Data (The code snippet can also be found with below search text)