<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Document</title> </head> <body> <script type="text/javascript" src="jquery-1.10.1.min.js"></script> <script> var arr=[1,3,5,7,9]; var obj={0:1,1:3,2:5,3:7,4:9,length:5}; //JS不能遍历伪数组,只能真的数组. arr.forEach(function(value,index) { console.log(index,value); }); /*obj.forEach(function(value,index) { console.log(index,value); });*/ //jQuery的(可以遍历伪数组的,还有真的数组都可以遍历啊) console.log("jQuery下面的"); $.each(arr,function(index,value) { console.log(index,value); }); $.each(obj,function(index,value) { console.log(index,value); }); </script> </body> </html>
jQuery第九篇 each方法
关注
打赏