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.
The original array
The item to append, which may be undefined or null
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] Copy
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]
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.