使用$.map()工具函数变更数组中的元素9-6

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>使用$.map()工具函数变更数组中的元素</title>
<script src="../lib/jquery-2.0.3.min.js" type="text/javascript"></script>
<style type="text/css">
	body{font-size:13px}
	div{margin:5px;padding:10px;border:solid 1px #666;background-color:#666;width:300px;}
</style>
<script type="text/javascript">
	$(function(){
		var strTmp = "筛选前数据:";
		var arrNum=[2,8,3,7,4,9,3,10,9,7,21];
		var arrGet = $.map(arrNum,function(ele,index){
			if( ele>5 && index<8){//元素值大于5且序号小于8
				return ele+1;
			}
		});
		strTmp +=arrNum.join();
		strTmp +="<br/><br/>筛选后数据:";
		strTmp +=arrGet.join();
		$("#divTip").append(strTmp); 
	})
</script>
</head>
<body>
	<div id="divTip"></div>
</body>
</html>

转载于:https://my.oschina.net/u/2552902/blog/543873

猜你喜欢

转载自blog.csdn.net/weixin_33862993/article/details/92326327
9-6