compare multidimensional array to find array with largest value javascript -


i have multidimensional array has name , integer values in them. need able compare integer value in each array in multidimensional array. how can compare , return array?

var totals = [     ['john', 'test', 45],     ['bob', 'tester', 75] ]; 

how can loop on arrays in "totals" array , return 1 largest integer value?

you use reduce. example:

var totals = [     ['john', 'test', 45],     ['john', 'test', 46],     ['john', 'test', 42],     ['john', 'test', 41] ];  var biggest = totals.reduce((a, b) => a[2] > b[2] ? : b); console.log(biggest); 

fiddle here


it should noted, if reduce() not supplied initial value, a becomes first, , b becomes second in first call.


Comments

Popular posts from this blog

php - How to display all orders for a single product showing the most recent first? Woocommerce -

asp.net - How to correctly use QUERY_STRING in ISAPI rewrite? -

angularjs - How restrict admin panel using in backend laravel and admin panel on angular? -