var numbers = [5, 458 , 120 , -215 , 228 , 400 , 122205, -85411]; var maxInNumbers = Math.max.apply(Math, numbers); var minInNumbers = Math.min.apply(Math, numbers);
栗子
$(document).ready(function () { //footer-guide dl 宽度 var dlLength = $('.footer-guide dl').length; var dlNum = (100/dlLength); var dlHeight = []; $('.footer-guide dl').each(function(i,e){ dlHeight.push($(e).height()); }); var maxHeight = Math.max.apply(Math, dlHeight); if(dlLength<=7){ $('.footer-guide dl').css('width',dlNum+'%') }else{ $('.footer-guide dl').css({'width':'14.28%','height':maxHeight}); } });
转载请注明:有爱前端 » JS 快速获取数据中的最大、最小值