Get max and min value from array in JavaScript

前端 未结 7 1181
小鲜肉
小鲜肉 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:43

    Find largest and smallest number in an array with lodash.

    var array = [1, 3, 2];
    var func = _.over(Math.max, Math.min);
    var [max, min] = func(...array);
    // => [3, 1]
    console.log(max);
    console.log(min);

提交回复
热议问题