Suppose I have this array of dictionaries:
var fruits = [{
"name" : "apple",
"color" : "red",
},
{
"name" : "banana",
"color" : "yellow"
}
#more dictionaries of fruits and their color
]
What would be the most efficient way to find, say, the color of the fruit "banana"? Is iterating over the list the only way?
var color
for fruit in fruits:
if(fruit["name"] == "banana"):
color = fruit["color"]
break