Wednesday, 21 August 2013

How to get biggest array element based on his second sub array value

How to get biggest array element based on his second sub array value

I have an JavaScript array of arrays:
[[-786, 2], [-783, 1], [-782, 5], [-781, 1], [-779, 2], [-778, 1], [-775,
1], [-774, 1], [-773, 1], [-771, 2], [-769, 1], [-767, 1], [-766, 1],
[-763, 2], [-760, 2]]
How can I get the biggest element based on value of second element in sub
array?
It case above I want to get element:
[-782, 5]
Because 5 is biggest second value in all sub arrays. If there will more
than one sub arrays with the bigger second value, I'd like to get first
one.
Mariusz

No comments:

Post a Comment