Ruby | Array uniq() function Last Updated : 06 Dec, 2019 Comments Improve Suggest changes Like Article Like Report Array#uniq() : uniq() is a Array class method which returns a new array by removing duplicate values in the array. Syntax: Array.uniq() Parameter: Array Return: a new array by removing duplicate values in the array Example #1 : Ruby # Ruby code for uniq() method # declaring array a = [18, 22, 33, nil, 5, 6] # declaring array b = [1, 4, 1, 1, 88, 9] # declaring array c = [18, 22, 50, 6] # uniq method example puts "uniq() method form : #{a.uniq()}\n\n" puts "uniq() method form : #{b.uniq()}\n\n" puts "uniq() method form : #{c.uniq()}\n\n" Output : uniq() method form : [18, 22, 33, nil, 5, 6] uniq() method form : [1, 4, 88, 9] uniq() method form : [18, 22, 50, 6] Example #2 : Ruby # Ruby code for uniq() method # declaring array a = ["abc", "nil", "dog"] # declaring array c = ["cat", nil] # declaring array b = ["cow", "gogoog", "dog"] # uniq method example puts "uniq() method form : #{a.uniq()}\n\n" puts "uniq() method form : #{b.uniq()}\n\n" puts "uniq() method form : #{c.uniq()}\n\n" Output : uniq() method form : ["abc", "nil", "dog"] uniq() method form : ["cow", "gogoog", "dog"] uniq() method form : ["cat", nil] Comment More infoAdvertise with us Next Article Ruby | Array uniq() function M mayank5326 Follow Improve Article Tags : Ruby Ruby-Methods Ruby Array-class Similar Reads Ruby | Array uniq!() function Array#uniq!() : uniq!() is a Array class method which removes duplicate elements from the array and returns only if there is duplicate element in the array. Syntax: Array.uniq!() Parameter: Array Return: removes duplicate elements from the array. Example #1 : Ruby # Ruby code for uniq!() method # de 1 min read Ruby | Array unshift() function Array#unshift() : unshift() is a Array class method which returns the shifted array with argumented element in place. Syntax: Array.unshift()Parameter: ArrayReturn: the shifted array with argumented element in place. Example #1 : Ruby # Ruby code for unshift() method # declaring array a = [18, 22, 3 2 min read Ruby | Array zip() function Array#zip() : zip() is a Array class method which Converts any arguments to arrays, then merges elements of self with corresponding elements from each argument. Syntax: Array.zip() Parameter: Array Return: merges elements of self with corresponding elements from each argument. Example #1 : Ruby # Ru 2 min read Ruby | Array slice!() function Array#slice!() : slice!() is a Array class method which seletes the element(s) given by an index or by a range. Syntax: Array.slice!() Parameter: Array Return: Deletes the elements given by an index or by a range. Example #1 : Ruby # Ruby code for slice!() method # declaring array a = [18, 22, 33, n 2 min read Ruby | Array shift() function Array#shift() : shift() is a Array class method which removes the first element of self and returns it or nil if the array is empty. Syntax: Array.shift() Parameter: Array Return: removes the first element of self and returns it or nil if the array is empty. Example #1 : Ruby # Ruby code for shift() 2 min read Ruby | Array slice() function Array#slice() : slice() is a Array class method which returns a subarray specified by range of indices. Syntax: Array.slice() Parameter: Array Return: a subarray specified by range of indices. Example #1 : Ruby # Ruby code for slice() method # declaring array a = [18, 22, 33, nil, 5, 6] # declaring 1 min read Ruby | Array take() function Array#take() : take() is a Array class method which returns the number of elements in the array. Syntax: Array.take() Parameter: Array Return: the number of elements in the array. Example #1 : Ruby # Ruby code for take() method # declaring array a = [18, 22, 33, nil, 5, 6] # declaring array b = [1, 1 min read Ruby | Array shuffle!() function Array#shuffle!() : shuffle!() is a Array class method which shuffles elements in self in place. Syntax: Array.shuffle!() Parameter: Array Return: shuffles elements in self in place. Example #1 : Ruby # Ruby code for shuffle!() method # declaring array a = [18, 22, 33, nil, 5, 6] # declaring array b 1 min read Ruby | Array shuffle() function Array#shuffle() : shuffle() is a Array class method which returns a new array with elements of self shuffle. Syntax: Array.shuffle() Parameter: Array Return: a new array with elements of self shuffle Example #1 : Ruby # Ruby code for shuffle() method # declaring array a = [18, 22, 33, nil, 5, 6] # d 2 min read Ruby | Array &() function Array#&() : &() is an Array class method which returns a new array containing unique elements common to the two arrays. Syntax: Array.&() Parameter: Array for the comparison Return: a new array containing unique elements common to the two arrays Example #1 : Ruby # Ruby code for &() 2 min read Like