I have an array of javascript objects:
var myObjects = [{figure: 3}, {figure: 5}, {figure: 2}];
I would like code that could give me a total of 10 based on the addition of all figure properties of objects in myObjects.
What I've Tried/Done
I could loop through using jQuery's .each() but I don't feel like iterating (and using a temporary 'store' variable) is the most elegant.
Obviously I could also do:
myObjects[0] + myObjects[1] etc. - but assume there is an arbitrary amount of objects.
I've done something similar for getting the minimum already:
var lowest = Math.min.apply(null, myObjects.map(function (x) {
return x['figure'];
}));
But would like the equivalent for total.