Given a JSON object such as this:
{
"something": {
"terms": [
{
"span": [
15,
16
],
"value": ":",
"label": "separator"
},
{
"span": [
16,
20
],
"value": "12.5",
"label": "number"
}
],
"span": [
15,
20
],
"weight": 0.005,
"value": ":12.5"
}
I would like write some javascript that would determine the index of the "term" that has a "label": "number". Ultimately I want to determine the "value" of the "term" that has a "label": "number", I know I can get that with something like this, where the index is known:
parsed = JSON.parse(result.trim());
var numberValue = parsed.terms[1].value;
My first thought is perhaps to just write a foreach loop and then return the numberValue when I arrive at an array object that has "label": "number".
Is there a more elegant and/or concise way to do this?
.filter()