Get max and min value from array in JavaScript

前端 未结 7 1179
小鲜肉
小鲜肉 2020-12-07 22:26

I am creating the following array from data attributes and I need to be able to grab the highest and lowest value from it so I can pass it to another function later on.

7条回答
  •  [愿得一人]
    2020-12-07 22:54

    if you have "scattered" (not inside an array) values you can use:

    var max_value = Math.max(val1, val2, val3, val4, val5);
    

提交回复
热议问题