js基础学习

   
        1.   ***遍历对象***

 用于遍历对象的属性,循环中的代码每执行一次,就会对象的属性进行一次操作

  for(var p in obj){ //p 为属性名称,obj[p]为对应属性的值

     代码块
                   }

例:

var n={a:1,b:2,c:3};
for (var key in n){
console.log(n[key]);
}

 输出结果为1     2     3

2.     ***调用函数***

 function A(){
       return[
             {a:1,
              b:2,
              c:3
              }
            };
       }

 
    调用上面函数中的数组
    

var n = A();//n为变量

   3.$.each遍历数组的属性值

var arr = [ "one", "two", "three", "four"]; 
$.each(arr, function(){ 
alert(this); 
});
 

 上面这个each输出的结果分别为:["one", "two", "three", "four"]   


   

猜你喜欢

转载自1175644344.iteye.com/blog/2299061