Search
If an array has nil items and we want to remove these nil items, then we can use compact.
nil
compact
As we can see, array2 does not have any nil items.
array2
Whereas, array1 still has the nil items.
array1
compact returns a new array which removes all nil items.