zoukankan      html  css  js  c++  java
  • E5中遍历数组的方法

    <!DOCTYPE html>
    <html lang="en">
    <head>
    	<meta charset="UTF-8">
    	<title>Document</title>
    </head>
    <body>
    	
    	<script type="text/javascript">
    		var arr = [11, 22, 33, 44, 55, 66];
    		// 遍历数组,原先的做法:使用for循环
    		// for(var i = 0; i < arr.length; i++) {
    		// 	console.log(arr[i]);
    		// }
    
    		// ES5中提供了:
    		// 1 forEach
    		// 2 map
    		// 
    		// 作用:都是来遍历数组的。
    		// map :不仅能遍历数组而且是能返回一个新的数组
    
    		// forEach 和 map 的参数:一个回调函数
    		// 回调函数的两个参数:
    		// 第一个参数表示:数组的当前值
    		// 第二个参数表示:当前的索引号
    		// arr.forEach(function(value, index) {})
    
    		/*arr.forEach(function(value, index) {
    			// console.log(value);
    			console.log("索引号为:" + index + ", 值为:" + value);
    
    			// this 指向了 window
    		});*/
    
    		var newArr = arr.map(function(value, index) {
    			// console.log("索引号为:" + index + ", 值为:" + value);
    			// return value * 2;
    			// return value * index;
    			return "a";
    		});
    
    		// newArr.forEach(function() {});
    		console.log(newArr);
    	</script>
    </body>
    </html>
    
  • 相关阅读:
    图片文件重命名
    MySql基础学习-Sql约束
    MySql基础学习-库表操作
    java内存模型
    数据库常用函数整理
    linux用户管理
    Db2数据库在Linux下的安装和配置
    图像金字塔
    特征值与特征向量
    齐次线性方程组
  • 原文地址:https://www.cnblogs.com/lsy0403/p/5898064.html
Copyright © 2011-2022 走看看