ES5-Array的新增方法
2024-10-08 13:46:07
Array.prototype.indexof(value):得到值在数组中的第一个下标
Array.prototype.lastIndexof(value):得到值在数组中的最后一个下标
Array.prototype.foreach(function(item,index){}):遍历数组
Array.prototype.map(function(item,index){}):遍历数组返回一个加工之后的数组,返回加工之后的值
Array.prototype.filter(function(item,index){}):遍历过滤一个新的数组,返回条件为true的值
例子:
var arr = [5,4,8,6,9,4,5,8,2,6,4,1,0];
console.log(arr.indexOf(5));
console.log(arr.lastIndexOf(5));
arr.forEach(function(item,index){
console.log('下标:'+index+','+'值:'+item);
});
console.log(arr.map(function(item,index){//返回一个将原数组中的值加10后的新数组
return item+10;
}));
console.log(arr.filter(function(item,index){//返回原数组中大于5的数为一个新的数组
return item>5;
}));
最新文章
- Android Intent
- 在Ubuntu14.04下安装运行Unity-tweak-tool报错scheme missing的解决办法
- HDU 3231 Box Relations
- MySQL 5.7 基于复制线程SQL_Thread加快恢复的尝试
- display inline or block
- Django2.X报错-------ModuleNotFoundError: No module named 'django.core.urlresolvers'
- iReport 5.6.0 启动闪退的问题 解决方案
- redis底层设计(一)——内部数据结构
- Nginx 添加 PHP 支持
- 004 Java的一次面试题,学长列举
- html页面出现&;#65279,影响布局
- c#中富文本编辑器Simditor带图片上传的全部过程(项目不是mvc架构)
- input框触发回车事件
- Mongodb 基础 查询表达式
- 牛客国庆集训派对Day3 B Tree
- C:基础知识
- spring boot 下载
- linux c 编程相关资料
- Ng第十七课:大规模机器学习(Large Scale Machine Learning)
- springmvc+mybatis 根据数据的id删除数据