Q:

compare multidimensional array to find array with largest value javascript

I have a multidimensional array that has name and integer values in them. I need to be able to compare the integer value in each array in the multidimensional array. how can I compare and return that array?
var totals = [
    ['john', 'test', 45],
    ['bob', 'tester', 75]
];

How can I loop over the arrays in the "totals" array and return the one with the largest integer value?

A:

You could use reduce. For 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] ? a : b);
console.log(biggest);

Fiddle here

It should be noted, that if reduce() is not supplied with an initial value, then a becomes the first, and b becomes the second in the first call.

