【发布时间】:2018-02-08 13:17:48
【问题描述】:
我的 Ruby 代码如下所示:
a = widgets["results"]["cols"].each_with_index.select do |v, i|
v["type"] == "string"
end
我只想获取v["type"] 为“字符串”的任何值的索引。 “结果”的外部数组有大约 10 个值(“cols”的内部数组有两个 - 其中一个具有“类型”的索引);我期望在这样的数组中返回两个结果:[7, 8]。但是,我得到这样的结果:
[[{"element"=>"processed", "type"=>"string"}, 7], [{"element"=>"settled", "type"=>"string"}, 8]]
我该怎么做?
【问题讨论】:
标签: arrays ruby select multidimensional-array indexing