ruby - Select a value from an array of hashes -


from array of hashes:

response = [   {"label"=>"cat", "name"=>"kitty", "id"=>189955},   {"label" => "dog", "name"=>"rex", "id" => 550081} ] 

is there way write like:

response.name.kitty 

to retrieve hash contains value:

{"label"=>"cat", "name"=>"kitty", "id"=>189955} 

you can -

response.select{|x| x["name"] == "kitty"}.first 

Comments

Popular posts from this blog

python - pip install -U PySide error -

arrays - C++ error: a brace-enclosed initializer is not allowed here before ‘{’ token -

cytoscape.js - How to add nodes to Dagre layout with Cytoscape -