I have the following array:
var array = []
array.push({payslipId: 1759});
array.push({payDate: "2019-04-19T00:00:00+00:00"});
array.push({periodsPerYear: 52});
array.push({taxPeriod: 2});
array.push({payslipId: 1760});
array.push({payDate: "2019-04-19T00:00:00+00:00"});
array.push({periodsPerYear: 52});
array.push({taxPeriod: 2});
What I am hoping to be able to do is create an array of distinct names, and where the values are numeric, the total off all in the above array would be shown.
The only way I can think to do this is to create a new array, and add each name
to it, then loop around the above array, and add to the value
to the name
, if the value is numeric.
I am not overly familiar with javascript, so am hoping there is a neater way, a bit like linq
in C#?
Desired output:
[{ payslipId: 3519 }, { periodsPerYear: 104} , { taxPeriod: 4}]