I have successfully found the results from a query and now i would like to find the sum of items that are in a field ‘referrals’ from the results of the same query. For instance, i get 7 items that matches the query parameters, how can i find the sum of items that are in the field ‘referrals’ from the 7 items? All suggestions will be appreciated. Here is my code:
wixData.query("Referrals")
.eq("referral", sumHrs)
.eq("paid",500)
.find()
.then( (results1) => {
let items = results1.items;
let item = items[0];
let referrals = item.referrals;
Thanks for the response. Apparently i have followed the steps on how to use a reducer and i don’t seem to understand. The reducer seems not to work. Kindly have a look at my code and advice according.
wixData.query("Referrals")
.eq("referral", sumHrs)
.eq("paid",500)
.find()
.then( (results1) => {
let items = results1.items;
let referrals = items.referrals;
const reducer = (accumulator, currentValue) => accumulator + currentValue;
let indirect=referrals.reduce(reducer, 0)