js使用技巧
来源:互联网 发布:开博软件注册码 编辑:程序博客网 时间:2024/05/29 16:23
一、获取数组中最大值
apply的参数数组化来获取数组的最大值
1)
function getMax(arr){
if(arr){
if(arr.length==1){
return arr[0];
}else{
return Math.max.apply(null,arr);
}
}
}
2)
Array.prototype.max = function(){
return Math.max.apply(null,this);
}
二、数组去重
Array.prototype.distinct = function(){
var result = [];
var json = {};
for(var i=0;i<this.length;i++){
if(!json[this[i]]){
result.push(this[i]);
json[i].push(this[i]) = 1;
}
}
return result;
}
- js使用小技巧
- JS使用技巧
- js使用小技巧
- Companion.JS使用技巧
- js使用基本技巧
- JS中的使用技巧
- js的使用技巧
- js使用技巧2
- js使用技巧3
- js使用技巧4
- js使用技巧5
- js使用技巧6
- js 使用和技巧
- JS 使用技巧
- js使用技巧
- js 使用技巧
- js使用技巧
- js使用技巧
- 浅谈远心镜头选择十大参数
- hdu4715之素数筛选
- 在bmp上添加字符
- 20个开源项目托管站点推荐
- android 给相片添加相应的时间
- js使用技巧
- 博士生撰写论文交流会
- (Struct)内存对齐
- Java Socket实战之二 多线程通信
- Linux主机资源监控与分析工具NMON
- JS计算几天后的日期
- texture与sprite的区别
- ubuntu用ssh登录centos,连接速度很慢
- hql中聚合函数查询