@H_301_1@我有以下数组:
response = [{"label"=>"cat","name"=>"kitty","id"=>189955},{"label" => "dog","name"=>"rex","id" => 550081}]
如何选择包含标签猫的哈希?我知道response.first会给我一样的结果,但是我想按照标签搜索.
谢谢!
德布
解决方法
response.find {|x| x['label'] == 'cat' } #=> {"label"=>"cat","id"=>189955}