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