JS获取数组最大值、最小值及长度的方法
作者:happy664618843 时间:2024-04-18 09:29:02
本文实例讲述了JS获取数组最大值、最小值及长度的方法。分享给大家供大家参考,具体如下:
//最小值
Array.prototype.min = function() {
var min = this[0];
var len = this.length;
for (var i = 1; i < len; i++){
if (this[i] < min){
min = this[i];
}
}
return min;
}
//最大值
Array.prototype.max = function() {
var max = this[0];
var len = this.length;
for (var i = 1; i < len; i++){
if (this[i] > max) {
max = this[i];
}
}
return max;
}
//数组长度
var array = new array(1,2,3,2,4,55,2);
alert(array.length);//输出7
希望本文所述对大家JavaScript程序设计有所帮助。
标签:JS,数组
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
Python Logging 日志记录入门学习
2022-05-17 14:48:39
python列表操作之extend和append的区别实例分析
2023-08-02 15:14:30
SQL Server数据库导入MySQL数据库体验
2009-01-20 16:07:00
解决golang 关于全局变量的坑
2024-02-17 05:46:02
python获取网页中所有图片并筛选指定分辨率的方法
2021-07-28 04:57:23
![](https://img.aspxhome.com/file/2023/6/71446_0s.jpg)
PyCharm添加Anaconda中的虚拟环境Python解释器出现Conda executable is not found错误解决
2022-02-24 23:51:03
![](https://img.aspxhome.com/file/2023/9/101059_0s.png)
Python面向对象特殊属性及方法解析
2022-05-19 15:16:06
![](https://img.aspxhome.com/file/2023/3/115483_0s.png)
python实现发送邮件及附件功能
2023-12-30 23:27:04
![](https://img.aspxhome.com/file/2023/0/109580_0s.jpg)
Ubuntu 18.04配置mysql以及配置远程连接的步骤
2024-01-14 14:54:39
![](https://img.aspxhome.com/file/2023/6/118476_0s.png)
使用httplib模块来制作Python下HTTP客户端的方法
2021-03-10 09:27:37
![](https://img.aspxhome.com/file/2023/1/110581_0s.jpg)
MSSQL数据加密解密代码
2023-07-08 18:45:30
利用Python+eval函数构建数学表达式计算器
2021-01-28 14:38:44
Python Web后端开发中的增查改删处理
2022-11-21 06:15:42
![](https://img.aspxhome.com/file/2023/5/118535_0s.png)
Python socket如何实现服务端和客户端数据传输(TCP)
2023-08-25 01:02:43
![](https://img.aspxhome.com/file/2023/3/127093_0s.png)
js实现文本框宽度自适应文本宽度的方法
2024-04-19 09:52:36
![](https://img.aspxhome.com/file/2023/7/136067_0s.jpg)
matplotlib绘制直方图的基本配置(万能模板案例)
2021-04-21 02:35:42
![](https://img.aspxhome.com/file/2023/9/128329_0s.png)
tensorflow之如何使用GPU而不是CPU问题
2023-07-06 13:05:48
一篇文章带你了解python正则表达式的正确用法
2023-01-05 19:20:30
![](https://img.aspxhome.com/file/2023/6/133806_0s.png)
Python Matplotlib绘图基础详细教程
2024-01-16 04:34:41
![](https://img.aspxhome.com/file/2023/0/119710_0s.jpg)
Python进行文件处理的示例详解
2021-12-08 10:51:04