jquery map()的用法--遍历数组
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title></title>
<meta charset="utf-8" />
<script src="jquery-3.3.1.js"></script>
<script>
var arr = [1, 2, 3, 4, 5, 6];
//$.map(arr, function (ele,index) {
// //alert(arguments.length);
// //alert(arguments[0] + '===' + arguments[1] + '===' + arguments[2]);
// alert(ele + '===' + index);
//});
//var arrs = $.map(arr, function (ele, index) {
// return ele * 2;
//});
var arrs = $.map(arr, function(ele, index) {
return index > 3 ? ele * 2 : ele;
});
alert(arrs);
</script>
</head>
<body>
</body>
</html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title></title>
<meta charset="utf-8" />
<script src="jquery-3.3.1.js"></script>
<script>
var arr = [1, 2, 3, 4, 5, 6];
//$.map(arr, function (ele,index) {
// //alert(arguments.length);
// //alert(arguments[0] + '===' + arguments[1] + '===' + arguments[2]);
// alert(ele + '===' + index);
//});
//var arrs = $.map(arr, function (ele, index) {
// return ele * 2;
//});
var arrs = $.map(arr, function(ele, index) {
return index > 3 ? ele * 2 : ele;
});
alert(arrs);
</script>
</head>
<body>
</body>
</html>