@pengzhanbo/utils - v3.9.0
    Preparing search index...

    Function drop

    • Drops the first n elements of an array.

      Returns a new array containing all elements of the input array except the first n. A non-finite n (NaN or Infinity) is treated as 0, floats are truncated, negative values are clamped to 0, and values greater than the array length are clamped to the length.

      从数组开头丢弃前 n 个元素。

      返回一个新数组,包含输入数组中除前 n 个之外的所有元素。非有限值 nNaNInfinity)按 0 处理,浮点数会被截断,负数按 0 处理,超过数组长度的值按数组长度处理。

      Type Parameters

      • T

        The type of elements in the array / 数组元素的类型

      Parameters

      • arr: readonly T[]

        The array to drop from. 要丢弃元素的数组

      • n: number = 1

        The number of elements to drop. Defaults to 1. 要丢弃的元素个数,默认为 1

      Returns T[]

      A new array without the first n elements. 去除前 n 个元素后的新数组

      O(n) time complexity - Array.prototype.slice

      O(n) 时间复杂度 - 使用 Array.prototype.slice

      drop([1, 2, 3, 4], 2)
      // => [3, 4]