Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

lodash
communitycreator

What is the _.drop() method in Lodash?

Shubham Singh Kshatriya

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

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:

Console

Code explanation

In the HTML tab:

  • In line 5, we import the lodash script.

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 n and initialize it with 3.
  • In line 8, we use the _.drop() method to drop n elements 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.

RELATED TAGS

lodash
communitycreator

CONTRIBUTOR

Shubham Singh Kshatriya

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

Keep Exploring