Noob question here!
I have an array with hashes that looks like this:
arr = [{id: 1, name: "Pedro"},{id: 2, name: "Pablo"}]
and want to have an array like this:
ids = [1,2]
I looked into using map or select like this:
ids = arr.each.select{|k,v| "id"==k}
But I can't figure it out.
Try the following:
ids = arr.map { |x| x[:id] }
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