我有一個object
變量具有以下值來訪問數組的元素:如何使用指數
[
{"a"=>nil, "b"=>79, "c"=>"mg/dL", "d"=>"high", "e"=>false},
{"a"=>80, "b"=>139, "c"=>"mg/dL", "d"=>"low", "e"=>true},
{"a"=>140, "b"=>199, "c"=>"mg/dL", "d"=>"moderate", "e"=>false},
{"a"=>200, "b"=>nil, "c"=>"mg/dL", "d"=>"high", "e"=>false}
]
我試圖通過索引並拿到鑰匙d
的價值,但該代碼崩潰
object.as_json.each_with_index.map { |range, i| range[i].d }
我得到undefined method d
以上
我怎樣才能得到的"d"
值的聲明?