I have an array of hashes from which I need the values of the hashes in a new array. The array of hashes look likes this, with a couple thousand of them.
array = [{:code=>"404"}, {:code=>"302"}, {:code=>"200"}]
I have tried to look this up but have only found out how to convert from a hash.
How would I go about doing this?
[{:code=>"404"}, {:code=>"302"}, {:code=>"200"}].flat_map(&:values)
#⇒ ["404", "302", "200"]
a=[{:code=>"404"}, {:code=>"302"}, {:code=>"200"}]
puts a.map{|x|x.values}.flatten.inspect
output
["404", "302", "200"]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With