I have an array @contacts
of hashes, each of which has the following keys:
:full_name
:city
:state
:email
How would I iterate through the array to return the :city
values uniquely? Below is my best attempt
@contacts.uniq {|hash| hash[:city]}
@contacts.map { |k| k[:city] }.uniq
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.