I have two JSON arrays with following values,
var data1 = [{
"keyword": "Jan","PotentialAmmount": 450000,"EarnedAmmount": 250000}, {
"keyword": "Feb","PotentialAmmount": 650000,"EarnedAmmount": 400000}, {
"keyword": "Mar","PotentialAmmount": 350000,"EarnedAmmount": 200000}];
var data2 = [{
"keyword": "Jan","PotentialAmmount": 150000,"EarnedAmmount": 200000}, {
"keyword": "Feb","PotentialAmmount": 250000,"EarnedAmmount": 100000}, {
"keyword": "Mar","PotentialAmmount": 450000,"EarnedAmmount": 100000}];
I want to add PotentialAmmount
and EarnedAmmount
of data2
to data1
in Javascript but am not sure how.
If I understood your question right, the function you want is:
It will make new object data3, that will have the same data structure and sum of the number fields. If you need to check the keywords the logic will be a little more complicated however.