<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>jquery_each和map的区别</title>
</head>
<script type="text/javascript" src="http://code.jquery.com/jquery-latest.js"></script>
<script>
// 定义一个伪数组
var obj ={0:1,1:3,2:5,3:7,4:9,length:5}
//定义一个数组
var arr =[1,3,5,7,9]
//遍历数组
arr.map(function (value, index, array) {
console.log(value, index, array)
})
效果图
//遍历伪数组
obj.map(function (value, index, array) {
console.log(value, index, array)
})
// map 有两个两个参数,第一个是要遍历的对象,第二个是回调
//回调的第一个参数value,第二个索引
$.map(arr,function (value,index) {
console.log(index,value)
})
</script>
<body>
</body>
</html>