jquery map方法总结
<script>
var arr=[1,3,6,8,4];
var obj={0:1,1:3,2:6,3:8,4:4};
arr.map(function(index,value,arr){//原生js map方法依次传入索引,值,数组
console.log(index,value,arr);
})
obj.map(function(index,value,arr){//原生js map方法不可遍历伪数组
console.log(index,value,arr);
})
$.map(arr,function(value,index){//jquery的map方法,先传数组,再传回调函数
console.log(index,value);})
var res1= $.map(obj,function(value,index){//jquery 的map方法遍历伪数组返回值为一个空数组
console.log(index,value);
})
var res2= $.each(obj,function(index,value){//each 方法遍历伪数组,则谁调用就返回谁
console.log(index,value);})
console.log(res1);
console.log(res2);
</script>
1.jquery 的map方法遍历伪数组返回值为一个空数组
2.jquery 的each方法遍历伪数组,谁调用就返回谁
3.原生js map方法无法遍历伪数组