Finding the max value of an attribute in an array of objects

前端 未结 13 2101
不思量自难忘°
不思量自难忘° 2020-11-22 08:05

I\'m looking for a really quick, clean and efficient way to get the max \"y\" value in the following JSON slice:

[
  {
    \"x\": \"8/11/2009\",
    \"y\": 0         


        
13条回答
  •  情歌与酒
    2020-11-22 08:28

    if you (or, someone here) are free to use lodash utility library, it has a maxBy function which would be very handy in your case.

    hence you can use as such:

    _.maxBy(jsonSlice, 'y');
    

提交回复
热议问题