for example:
[ (id=>1, email=>'[email protected]', name=>'tim'),
(id=>2, email=>'[email protected]', name=>'joe'),
(id=>3, email=>'[email protected]', name=>'dan') ]
How can I extract the email column and put it in its own array?
Let's call your array users
. You can do this:
users.map{|u| u[:email]}
This looks at the hashes one by one, calling them u
, extracts the :email
key, and returns the results in a new array of user emails.
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