The _.head()
method in Lodash is used to get the first element of an array.
_.head(array)
This method accepts the following parameter:
array
: This is the array to be queried.This method returns the first element of the array.
Let’s look at an example of the _.head()
method in the code snippet below:
In the HTML tab:
lodash
script.In the JavaScript tab:
numbers
and populate it with a few values._.head()
method to get the first element of the array.In the output, we see 5
, which is the first element of the array.