Finding the max value of an attribute in an array of objects and return the entire object

前端 未结 5 1705
暗喜
暗喜 2021-01-22 12:04

I know a similar question has been asked here: Finding the max value of an attribute in an array of objects, but with that method there is no way to return the entire object con

5条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2021-01-22 12:44

    If A is the array of objects.

    function return_Max_Object(A)
    {
     var M = -Infinity;
     var Max_index = -1;
     for(var i =0;iM) 
      {
        M = A[i].value;
        Max_index = i;
      }
     }
     return A[Max_index];
    }
    

提交回复
热议问题