for foreach

  1. for

     var key;
     var arr = [
         a = 1,
         b = 2
     ];
     for(key in arr) {
         console.log(arr[key]);
     }
    
  2. foreach

     var arr = [
         a = 1,
         b = 2
     ];
     var sum = 0;
     arr.forEach(function(val,key,arr){
       console.log(arr[key] === val);
       sum += val;
     });
     console.log(sum);
    
@耿志环 2012-∞ 冀ICP备17033181号, powered by Gitbook修订: 2018-05-23 16:25:59

results matching ""

    No results matching ""