drop()
drop<
T>(array,count):T[]
Creates a slice of array with n elements dropped from the beginning.
Type Parametersโ
T: Tโ
The type of elements in the array.
Parametersโ
array: readonly T[]โ
The array to query.
count: numberโ
The number of elements to drop.
Returns: T[]โ
A new array with the first count elements removed.
Throwsโ
RangeError If count is negative.
Sinceโ
2.0.0
Performanceโ
O(n) time & space, single slice operation.
Also known asโ
drop (Lodash, es-toolkit, Remeda, Ramda, Effect) ยท โ (Radashi, Modern Dash, Antfu)
Exampleโ
const numbers = [1, 2, 3, 4, 5];
drop(numbers, 2);
// => [3, 4, 5]
drop(numbers, 0);
// => [1, 2, 3, 4, 5]
How it works?โ
Use Casesโ
Implement cursor-based pagination ๐โ
Skip already-fetched items when loading more content. Essential for infinite scroll or "Load More" buttons.
const allMessages = ["msg1", "msg2", "msg3", "msg4", "msg5", "msg6"];
const alreadyLoaded = 3;
const nextBatch = drop(allMessages, alreadyLoaded);
// => ["msg4", "msg5", "msg6"]
Skip metadata rows in imported dataโ
Remove header lines from CSV or spreadsheet imports. Critical for data processing pipelines.
const csvRows = [
"Name,Age,City", // Header
"Alice,25,Paris",
"Bob,30,Lyon",
];
const dataRows = drop(csvRows, 1);
// => ["Alice,25,Paris", "Bob,30,Lyon"]
Exclude first N results from searchโ
Remove promoted or pinned items to get organic results. Useful for search engines or content feeds.
const searchResults = [
{ title: "Sponsored: Product A", sponsored: true },
{ title: "Sponsored: Product B", sponsored: true },
{ title: "Organic Result 1", sponsored: false },
{ title: "Organic Result 2", sponsored: false },
];
const organicOnly = drop(searchResults, 2);
// => [{ title: "Organic Result 1" }, { title: "Organic Result 2" }]