const arr = [1, 2, 3, 4, 5, 6, 7];
//remove first element (n=1) by default
const arr1 = _.drop(arr);
//remove first 3 elements
const arr2 = _.drop(arr, 3);
//remove first 5 elements
const arr3 = _.drop(arr, 5);
We can easily remove first n items from an array using _.drop method if we are using Lodash javascript library in our project. The syntax and description of _.drop is as below.
Basic syntax of _.drop is as below which can be used to drop first n items from given array.
_.drop(Array, n=1)
Array: This argument is of array type and this contains the values that you want to remove from this array. This is a required parameter.
n: Here we pass an integer type value. This is an options argument. The default value of n is 1 means if you do not pass any value it will remove very first element from the array.
Example Demo for _.drop
0 Comments