forEarch 和 for in

forEarch 遍历数组,遍历的过程中不能被终止,必须每一个值遍历一遍后才能停下来,for  in遍历对象中的属性

代码:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>foreach</title>
</head>
<body>
   
</body>
<script>
  var myArry =[1,2,3,4];
//   myArry.desc ='four';
  myArry.forEach((value,index,arr)=>{
  console.log(value,index);
 
  });
   var myArry={
       name:'zxw',
       email:'123',
       phone:'345'
   }
   for(var  value  in myArry ) {
    console.log(value);  
   }
</script>
</html>

  输出:

 

posted @ 2018-08-31 17:10  1点  阅读(456)  评论(0编辑  收藏  举报