首页 > 代码库 > $.each()的用法

$.each()的用法

var obj = { one:1, two:2, three:3}; 
$.each(obj, function(key, val) { 
    console.log(key);//one   two   three
    console.log(val); //1 2 3
});

var arr1 = [ "aaa", "bbb", "ccc" ]; 
    $.each(arr1, function(i,val){ 
    console.log(i); //0 1 2
    console.log(val);//aaa  bbb  ccc
    
});

 

$.each()的用法