I have a json object as below:
{
"critiquesAvg": 4.75: ,
"critiques":[
{
'author': 'John Does',
'comment': "I like it",
'stars' : 5
},
{
'author': 'Jacob Works',
'comment': "I like it too",
'stars' : 4.5
}
]
}
I need to calculate the value (4.75) of critiquesAvg dynamically by averaging the stars property value of the critiques array.
Could somebody help me with it?
EDIT: Apologies, the actually issue I was having was like below:
var dealers = [{
"id", 1874
"critiquesAvg": 4.75 ,
"critiques":[
{
'author': 'John Does',
'comment': "I like it",
'stars' : 5
},
{
'author': 'Jacob Works',
'comment': "I like it too",
'stars' : 4.5
}
]
},
{
"id": 1345,
"critiquesAvg": 5 ,
"critiques":[
{
'author': 'John Does',
'comment': "I like it",
'stars' : 5
},
{
'author': 'Jacob Works',
'comment': "I like it too",
'stars' : 5
}
]
}
];
and here I wanted to calculate the values of the critiquesAvg property dynamically based on the number of average of the critiques for a particular dealer's data.
critiquesAvgusingObject.definePropertyfunction?critiquesAvgasdata.critiquesAvg, havingcritiquesAvgcalculated dynamically based on the number of critique objects in thecritiquesarray.