How to traverse an array and merge the objects in the array if the values of the objects in the array are equal

1. Traverse an array and merge the objects in the array if the values of the objects in the array are equal

//
var a = [
    {
      date:"2018-7-24",
      value:2
    },
    {
      date:"2018-7-24",
      value:5
    },
    {
      date:"2018-7-25",
      value:5
    },
    {
      date:"2018-7-25",
      value:5
    },
]
//
res = [
    {
      date:"2018-7-24",
      value:7
    },
    {
      date:"2018-7-25",
      value:10
    },

]

if you want to break your head, you still don"t know if anyone has a better way. Thank you very much!

Mar.29,2021

Why is there always such a problem these days.


arr.reduce((previousValue, currentValue, currentIndex, arr) => {

})
Menu