I have an js object JSON
var s = [
{
"MONTH":" 2018-01",
"DEPARTMENT":"Legals",
"EMPLOYEE":"Smith A.",
"AMOUNT":"14289.66"
},
{
"MONTH":" 2018-01",
"DEPARTMENT":"Legals",
"EMPLOYEE":"Jonson B.",
"AMOUNT":"7408.05"
},
{
"MONTH":" 2018-01",
"DEPARTMENT":"Legals",
"EMPLOYEE":"Lee C.",
"AMOUNT":"10102.98"
}
]
I want to count summ of AMOUNT property and do it by using next (I used code from source stackoverflow_count_summ):
s.sum = function(items, prop){
return items.reduce( function(a, b){
return a + b[prop];
}, 0);
};
sTotal = s.sum(s, 'AMOUNT');
but I get an error message: "TypeError: s.sum is not a function"
How can I get summ of 'AMOUNT' values through the object?