xgqfrms™, xgqfrms® : xgqfrms's offical website of cnblogs! xgqfrms™, xgqfrms® : xgqfrms's offical website of GitHub!

how to find max value of array in js All In One

how to find max value of array in js All In One

Math.max

const data = ["37.02","15.75","11.22","7.88","6.50","4.83","3.45","2.56","1.93","1.51","1.20","0.95","0.79","0.64","0.54","0.42","0.35","0.32","0.29","43.17"];
// (20) ["37.02", "15.75", "11.22", "7.88", "6.50", "4.83", "3.45", "2.56", "1.93", "1.51", "1.20", "0.95", "0.79", "0.64", "0.54", "0.42", "0.35", "0.32", "0.29", "43.17"]

Math.max(data.map(item => (Math.ceil(parseInt(item) / 10) * 10)));
// NaN
data.map(item => (Math.ceil(parseInt(item) / 10) * 10));
// (20) [40, 20, 20, 10, 10, 10, 10, 10, 10, 10, 10, 0, 0, 0, 0, 0, 0, 0, 0, 50]

Math.max(...data.map(item => (Math.ceil(parseInt(item) / 10) * 10)));
// 50

reduce



array & max & min

Array.prototype.max = function() {
  return Math.max.apply(null, this);
};

Array.prototype.min = function() {
  return Math.min.apply(null, this);
};

refs

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/max

https://stackoverflow.com/questions/1669190/find-the-min-max-element-of-an-array-in-javascript



©xgqfrms 2012-2020

www.cnblogs.com/xgqfrms 发布文章使用:只允许注册用户才可以访问!

原创文章,版权所有©️xgqfrms, 禁止转载 🈲️,侵权必究⚠️!


posted @   xgqfrms  阅读(47)  评论(1编辑  收藏  举报
编辑推荐:
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
阅读排行:
· DeepSeek 开源周回顾「GitHub 热点速览」
· 记一次.NET内存居高不下排查解决与启示
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· .NET10 - 预览版1新功能体验(一)
历史上的今天:
2020-07-20 图解 HTTP, 图解 HTTPS, 图解 HTTP/2, 图解 HTTP/3, 图解 QUIC All In One
2020-07-20 Async Programming All in One
2020-07-20 js 如何打印出 prototype 的查找路径 All In One
2019-07-20 image no extensions name & base 64 image
2019-07-20 component & slot
2018-07-20 WeakSet , WebSocket API
2016-07-20 你不知道的 JavaScript 细节: not defined !== undefined
点击右上角即可分享
微信分享提示