reduce will return a single value with one pass through the array.
var a= [{
curr:"XEK", antal:2
},{
curr:"SEK", antal:7
},{
curr:"JPY", antal:1
},{
curr:"DKK", antal:1
}];
var min= a.reduce(function(a, b){
return a.antal> b.antal? a:b;
});
*alert('curr='+min.curr+', antal='+min.antal);
returned value>> curr= SEK, antal= 7 *
for older browsers you can shim reduce-
if(![].reduce){
Array.prototype.reduce= function(fun, temp, scope){
var T= this, i= 0, len= T.length, temp;
if(typeof fun=== 'function'){
if(temp== undefined) temp= T[i++];
while(i < len){
if(i in T) temp= fun.call(scope, temp, T[i], i, T);
i++;
}
}
return temp;
}
}