【问题标题】:Find the Max and Min element out of all the nested arrays of nested arrays in javascript [duplicate]从javascript中嵌套数组的所有嵌套数组中查找Max和Min元素[重复]
【发布时间】:2021-10-24 23:38:46
【问题描述】:

查找嵌套数组的最大值和最小值

var arry=[1,2,[14,56,34,[48,98]],[14,16,11,[18,81]],34,35]

【问题讨论】:

    标签: javascript arrays


    【解决方案1】:

    您可以先将数组展平,然后采用扩展值的所需方法。

    const
        array = [1, 2, [14, 56, 34, [48, 98]], [14, 16, 11, [18, 81]], 34, 35],
        flat = array.flat(Infinity),
        min = Math.min(...flat),
        max = Math.max(...flat);
    
    console.log(min, max);

    【讨论】:

    猜你喜欢
    • 2018-05-21
    • 1970-01-01
    • 1970-01-01
    • 2020-12-04
    • 2021-08-27
    • 1970-01-01
    • 2021-10-14
    • 2020-12-10
    • 1970-01-01
    相关资源
    最近更新 更多