Given the following data structure:
data = {'NameValues':[
{'Name':'Field 1', 'Values':['Data 1']},
{'Name':'Field 2', 'Values':['Data 2']},
{'Name':'Field 3', 'Values':['Data 3']},
{'Name':'Field 4', 'Values':['Data 4']},
{'Name':'Field 5', 'Values':['Data 5']}
]}
How can find by name and get the value of an element? e.g. get the values for Field 3.
In Ruby I would use this:
p hash['NameValues'].find{ |h| h['Name'] == 'Field 3'}['Values']
#=> ["Data 3"]
This iterates through the NameValues array until a matching element is found. I can then get the Values from the returned element.
Regards