Function lastItem

Returns the last item of an array.

lastItem([1, 2, 3]); // 3
lastItem([]); // undefined
  • Type Parameters

    • V

      The item type.

    • S extends readonly V[]

      The source array type.

    Parameters

    • source: S

      The array.

    Returns At<-1, S>

    The last item of the array. If the array is empty, undefined is returned.