Max value of a multidimensional array javascript

前端 未结 7 2327
太阳男子
太阳男子 2021-02-09 18:35

I have a multidimensional array of x columns and y rows. How can I find the min and the max value of the matrix? Example:

[[1,  37.8, 80.8, 41.8],
[2,  30.9, 69.         


        
7条回答
  •  粉色の甜心
    2021-02-09 19:26

    let

    var arr = [[2,3], [4,5]]; // a multidimensional array
    

    then get an array with each row's maximum with

    var maxRow = arr.map(function(row){ return Math.max.apply(Math, row); });
    

    and the overal maximum with

    var max = Math.max.apply(null, maxRow);
    

提交回复
热议问题