Skip to main content

drop

Returns a new array with the first n elements removed from the array.

If no additional argument is provided, returns a new array with only the first element removed.

If the count to remove is greater than the array length, returns an empty array.

If the count to remove is negative, returns the original array.


Code

🔗 View source code


Benchmark

  • hz: Operations per second
  • mean: Average response time (ms)
NamehzmeanPerformance
modern-kit/drop7,920,294.480.0001fastest
lodash/drop2,854,814.000.0004slowest
  • modern-kit/drop
    • 2.77x faster than lodash/drop

Interface

typescript
function drop<T>(arr: T[], count: number = 1): T[]

Usage

typescript
import { drop } from '@modern-kit/utils';

const arr = [1, 2, 3, 4, 5];
console.log(drop(arr)); // [2, 3, 4, 5]
console.log(drop(arr, 0)); // [1, 2, 3, 4, 5]
console.log(drop(arr, 2)); // [3, 4, 5]
console.log(drop(arr, 7)); // []