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

jsf - "PropertyNotWritableException: Illegal Syntax for Set Operation" error when setting value in bean -

arrays - Algorithm to find ideal starting spot in a circle -

php - Autoloader issue not returning Class -