Lodash _.drop() Method
Last Updated :
25 Oct, 2023
Lodash _.drop() method is used to drop the elements in a given array.
Syntax:
_.drop(array, number);
Parameters:
- Array: It is the original array from which the elements are to be removed.
- Number: It is the number of elements to be removed from the array.
Note: The elements are removed from the index 0 of the array.
Return Value:
It returns the sliced array.
Example 1: In this example, we are dropping 2 elements of an array and printing the rest of the elements by the use of the _.drop() method.
Javascript
const _ = require( "lodash" );
let array = [ "a" , "b" , "c" , "d" ]
let newArray = _.drop(array, 2)
console.log( "before : " , array)
console.log( "after : " , newArray)
|
Output:
Example 2: In this example, we are dropping 10 elements of an array and the number od dropping elements is higher than it’s length so it will print the empty array.
Javascript
let _ = require( "lodash" );
let array = [1, 2, "a" , "b" , "c" , "d" ]
let newArray = _.drop(array, 10)
console.log( "before : " , array)
console.log( "after : " , newArray)
|
Output:
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...