How can I “extract” values from a multidimensional array in a smart way?

前端 未结 3 1187
滥情空心
滥情空心 2021-01-11 10:44

I am using Ruby on Rails 3.2.2 and Ruby 1.9.2.

Given the following multidimensional Array:

[[\"value1\", \"value1_other\"], [\"value2\",         


        
3条回答
  •  长发绾君心
    2021-01-11 11:10

    >> array = [["value1", "value1_other"], ["value2", "value2_other"], ["value3", "value3_other"]]
    => [["value1", "value1_other"], ["value2", "value2_other"], ["value3", "value3_other"]]
    >> array.map { |v| v[0] }
    => ["value1", "value2", "value3"]
    

提交回复
热议问题