ES5给数组对象添加了一些方法, 常用的5个:

1. Array.prototype.indexOf(value) : 得到值在数组中的第一个下标

2. Array.prototype.lastIndexOf(value) : 得到值在数组中的最后一个下标

3. Array.prototype.forEach(function(item, index){}) : 遍历数组

4. Array.prototype.map(function(item, index){ }) : 遍历数组返回一个新的数组

5. Array.prototype.filter(function(item, index){ }) : 遍历过滤出一个新的子数组

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>04_Array扩展</title>
</head>
<body>
<!--
. 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的值
-->
<script type="text/javascript">
/*
需求:
1. 输出第一个6的下标
2. 输出最后一个6的下标
3. 输出所有元素的值和下标
4. 根据arr产生一个新数组,要求每个元素都比原来大10
5. 根据arr产生一个新数组, 返回的每个元素要大于4
*/ var arr = [, , , , , ];
console.log(arr.indexOf());//2
//Array.prototype.lastIndexOf(value) : 得到值在数组中的最后一个下标
console.log(arr.lastIndexOf());//5 //Array.prototype.forEach(function(item, index){}) : 遍历数组
arr.forEach(function (item, index) {
console.log(item, index);
}); //Array.prototype.map(function(item, index){}) : 遍历数组返回一个新的数组,返回加工之后的值
var arr1 = arr.map(function (item, index) {
return item +
});
console.log(arr, arr1); //Array.prototype.filter(function(item, index){}) : 遍历过滤出一个新的子数组, 返回条件为true的值
var arr2 = arr.filter(function (item, index) {
return item >
});
console.log(arr, arr2); </script>
</body>
</html>

最新文章

  1. 部署React+webpack工程的步骤
  2. 简单阐述下OC中UIImage三种创建方式~~~
  3. shell 脚本技巧
  4. eclispe中在线安装maven插件
  5. NLTK中文语料库sinica_treebank
  6. WCF-复合类型使用;传输图片
  7. IOS--手势控制的使用
  8. 水果姐逛水果街Ⅰ(codevs 3304)
  9. 从文章&quot;避免复制与粘贴&quot;到文章&quot;Extract Method&quot;的反思(3)
  10. 学习下关于ViewStub实例的用法及带Drawable的TextView的妙用
  11. [C++程序设计]函数的递归调用
  12. python-----运算符及while循环
  13. C#后台调用浏览器打开下载连接地址的三种方法
  14. R语言命令行参数
  15. Linux System Programming --Chapter Six
  16. IaaS,PaaS,SaaS 的区别
  17. Linux 典型应用之远程连接SSH
  18. 谈谈 在 .Net 生态里为什么没有 Hadoop 系列 ?
  19. ucos串口通讯模块设计
  20. SQL Server上DBLINK的创建,其实很简单!(上)

热门文章

  1. 记一次批量修改SQLServer表数据
  2. 反射与类加载之ClassLoader与类加载器(二)
  3. 2018-9-30-dotnet-core-通过修改文件头的方式隐藏控制台窗口
  4. ie兼容小知识点
  5. 酷狗mac版如何新建歌单?酷狗mac版收藏歌单方法
  6. leetcood学习笔记-83-删除链表中的重复元素
  7. Dart编程运算符
  8. Python3 测试报告BeautifulReport中添加截图
  9. Apache负载均衡
  10. go modules学习