码迷,mamicode.com
首页 > 编程语言 > 详细

JavaScript 取数组最值的方法

时间:2015-04-01 15:09:14      阅读:128      评论:0      收藏:0      [点我收藏+]

标签:

1、用Math的max,min函数
    var array = [10,2,3,4,5,6,30,8,9];
    Math.max.apply(null,array);
    Math.min.apply(null,array);

//    Math.max.apply(Math或者{},array);
//    Math.min.apply(Math或者{},array);

2、先排序,在pop,
    array .sort();
    alert(b.pop()); //最大值
    alert(b.shift());//最小值

  

JavaScript 取数组最值的方法

标签:

原文地址:http://www.cnblogs.com/sallet/p/4383767.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!