I have a JSON array that looks something like this.
[
{"name":"Idaho","state":{"id":1,"name":"A"}},
{"name":"Wyoming","state":{"id":1,"name":"A"}},
{"name":"Montana","state":{"id":2,"name":"B"}},
{"name":"South Dakota","state":{"id":1,"name":"B"}}
]
How can I use Ruby to only display the value of A?
I donβt think sort_by will be the answer, because what I have below just sorts them alphabetically. I want to completely exclude all results from B.
.sort_by { |a| [a.state.name] }
What would be the most efficient way to do this in a .rb file?
I solved my question. This is how I achieved what I wanted.
.select { |a| a.state.name == "A" }
source
share