How to sum two object values in javascript

后端 未结 7 590
长发绾君心
长发绾君心 2021-01-13 18:25

I\'m stuck how i sum two object like this:

obj1 = { 
  \'over_due_data\': 10,
  \'text_data\': 5
} 

obj2 = {
  \'over_due_data\': 20,
  \'text_data\': 5
}
<         


        
7条回答
  •  清酒与你
    2021-01-13 19:13

    Try this might be helpful

    obj1 = {
      'over_due_data': 10,
      'text_data': 5
    }
    obj2 = {
      'over_due_data': 20,
      'text_data': 5
    }
    var obj ={}
    Object.keys(obj1).map(function(a){
      obj[a] = obj1[a] +obj2[a]
    
    })
    console.log(obj)

提交回复
热议问题