queryReduce

Reduces query columns just like in array or collection

queryReduce(query, closure [, initialValue]) → returns any

Member Function Syntax

query.reduce(closure [, initialValue])

queryReduce Argument Reference

query query
Required

closure function
Required

initialValue any

Links more information about queryReduce

Examples sample code invoking the queryReduce function


Reduce column to total

Sum one query column

fruits = queryNew("fruit,amount",
    	"varchar,integer", [{
    		"fruit": "apples",
    		"amount": 15
    	}, {
    		"fruit": "pineapples",
    		"amount": 3
    	}, {
    		"fruit": "strawberries",
    		"amount": 32
    	}]
    );
    total_fruits = queryReduce(fruits,function(a,b) {
        return a + b.amount;
    },0);
    
    writeOutput(total_fruits);

Expected Result: 50


Fork me on GitHub