You can also use Underscore.js which is basically a swiss-knife library to manipulate collections. Using _.filter
, _.pluck
, _.reduce
you can do SQL-like queries.
var data = [{"x": 2, "y": 0}, {"x": 3, "y": 1}, {"x": 4, "y": 1}];
var posData = _.filter(data, function(elt) { return elt.y > 0; });
// [{"x": 3, "y": 1}, {"x": 4, "y": 1}]
var values = _.pluck(posData, "x");
// [3, 4]
var sum = _.reduce(values, function(a, b) { return a+b; });
// 7
Underscore.js works both client-side and server-side and is a notable library.
You can also use Lo-Dash which is a fork of Underscore.js with better performances.