@chip/cstd - v0.0.8
    Preparing search index...

    Function safeAppend

    • Safely append an item which may not be defined to an array. This function returns a copy of the source array and does not mutate the original.

      Type Parameters

      • T

      Parameters

      • arr: T[]

        The original array

      • item: T | null | undefined

        The item to append, which may be undefined or null

      Returns T[]

      A new array with the item appended if it is defined; otherwise, the original array

      safeAppend([1, 2, 3], 4); // [1, 2, 3, 4]
      safeAppend([1, 2, 3], null); // [1, 2, 3]
      safeAppend([1, 2, 3], undefined); // [1, 2, 3]