uft
    Preparing search index...

    Function clearArray

    • Removes all elements from an array by mutating it in-place.

      Type Parameters

      • T extends unknown[]

      Parameters

      • array: T | null | undefined

        The array to clear.

      Returns T

      A new array containing the elements that were removed.

      const array = [1, 2, 3, 4, 5]
      const removed = clearArray(array)
      console.log(array, removed) // [] , [1, 2, 3, 4, 5]

      If there are no elements to remove, an empty array is returned.

      const array = []
      const removed = clearArray(array)
      console.log(array, removed) // [] , []
      console.log(array === removed) // false