Fast way to get the min/max values among properties of object

后端 未结 11 1929
伪装坚强ぢ
伪装坚强ぢ 2020-12-01 00:44

I have an object in javascript like this:

{ \"a\":4, \"b\":0.5 , \"c\":0.35, \"d\":5 }

Is there a fast way to get the minimum and maximum v

11条回答
  •  囚心锁ツ
    2020-12-01 01:19

    You can also try with Object.values

    const points = { Neel: 100, Veer: 89, Shubham: 78, Vikash: 67 };
    
    const vals = Object.values(points);
    const max = Math.max(...vals);
    const min = Math.min(...vals);
    console.log(max);
    console.log(min);

提交回复
热议问题