首页 > 编程语言 > 详细

javascript找出数组中的最大值

时间:2018-03-30 10:14:02      阅读:203      评论:0      收藏:0      [点我收藏+]
  • 代码:
    Array.prototype.max = function(){
    var max = 0
    for(var i=0;i<this.length;i++){
        if(max<this[i]){
            max = this[i]
        }
    }
    return max
    }
  • 测试:
    var arr = [1,2,5,3,2,4]
    console.log(arr.max())
  • 输出:
    5
  • javascript找出数组中的最大值

    原文:http://blog.51cto.com/12173069/2092766

    (0)
    (0)
       
    举报
    评论 一句话评论(0
    关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
    © 2014 bubuko.com 版权所有
    打开技术之扣,分享程序人生!