我有这样的数组
records =
[
["a","1"],
["b","2"],
["c","3"]
]
Run Code Online (Sandbox Code Playgroud)
我想拉3号,因为我知道我在搜索"c"的值.
我试过这个,但没有运气
search_for = 'c'
test = records.select{ |x| x=search_for}
Run Code Online (Sandbox Code Playgroud)
我回到整个阵列
您正在寻找Array#assoc:
records.assoc(search_for).last
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
83 次 |
| 最近记录: |