I have an array of objects that appears as follows:
var dataArray = [{ "moment": "18 January 2019", "val": 53 },
{ "moment": "18 January 2019", "val": 69 },
{ "moment": "18 January 2019", "val": 52 },
{"moment": "21 January 2019", "val": 52 },
{ "moment": "21 January 2019", "val": 52 },
{ "moment": "21 January 2019", "val": 52 }]
What I would like to do is to put in a new array the value of the element moment and the average of val for that moment. eg:
result =[{moment: "18 January 2019", "val": 58},
{moment: "21 January 2019", "val": 52}].
For now I managed to put a single occurence of each date in the new array result but I am having hard time to put the average since I don't know how to make the difference between values for a date from values for another date. Any help would be appreciated.
Peace
for data in dataArraydivided bydataArray.length. #2 do your other iteration(s)