I have an array with a lot of elements. Each element is like:
e1 = {
data: 12345,
month: 8,
year: 2018
}
And with this array I want to create a new array of elements of the same type but with the sum of each data of the element which have the same month and the same year.
For example: If my array is:
myArray = [
{
data: 1,
month: 7,
year: 2018
},
{
data: 2,
month: 8,
year: 2018
},
{
data: 3,
month: 8,
year: 2018
}
]
I want this new array:
myNewArray = [
{
data: 1,
month: 7,
year: 2018
},
{
data: 5,
month: 8,
year: 2018
}
]
Could you help me with that by using javascript function ?