What is the _.drop() method in Lodash?
Overview
The _.drop() method in Lodash creates a slice of an array by dropping the n number of elements from the beginning of the array.
Syntax
_.drop(array, n)
Parameter values
This method accepts the following parameters:
array: This is the array that needs to be sliced.n: This is the number of elements that need to be dropped.
Return value
This method returns a slice of an array.
Code example
Let’s look at an example of the _.drop() method in the code snippet below:
Code explanation
In the HTML tab:
- In line 5, we import the
lodashscript.
In the JavaScript tab:
- In line 2, we create an array and initialize it with a few values.
- In line 5, we create a variable
nand initialize it with 3. - In line 8, we use the
_.drop()method to dropnelements from the beginning of the array. - In line 11, we print the output to the console.
Output
We see a slice in which n number of elements have been dropped from the beginning of the array.