A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://www.geeksforgeeks.org/javascript/lodash-_-drop-method/ below:

Lodash _.drop() Method - GeeksforGeeks

Lodash _.drop() Method

Last Updated : 30 Aug, 2024

Lodash _.drop() method is used to drop the elements in a given array.

Syntax:
_.drop(array, number);
Parameters:

Note: The elements are removed from the index 0 of the array.

Return Value:

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
// Requiring the lodash library
const _ = require("lodash");

// Original array
let array = ["a", "b", "c", "d"]

// using drop() method to remove
// first two elements
let newArray = _.drop(array, 2)

// Printing original array 
console.log("before : ", array)

// Printing array after applying
// drop function
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
// Requiring the lodash library
let _ = require("lodash");

// Original array
let array = [1, 2, "a", "b", "c", "d"]

// Using drop() method to remove
// first 10 elements
let newArray = _.drop(array, 10)

// Printing original array 
console.log("before : ", array)

// Printing array after applying
// drop function
console.log("after : ", newArray)

Output:



RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4