Javascript examples for Array:sort
Getting variable name with highest value using array sort and custom function
<html> <head> <meta name="viewport" content="width=device-width, initial-scale=1"> <script type="text/javascript"> window.onload=function(){/*from w w w . j a va 2s . com*/ var _myDemoArray = [ {name:'Gain_weight', value:0.01}, {name:'Gain_weather', value:0.02}] var _getSortedElem = _myDemoArray.sort(function(a,b){ return b.value -a.value; }); console.log(_getSortedElem[0].name); } </script> </head> <body> </body> </html>