uniq to remove all duplicate elements

If an array has duplicate items then we can use uniq method to remove all the duplicates.

As we can see array2 does not have any duplicate items. Note that uniq does not change the original array. The original array1 is still containing duplicate items. compact method returns a new array which has duplicate items removed.