zl程序教程

您现在的位置是:首页 >  其它

当前栏目

forEarch 和 for in

for in
2023-09-11 14:22:19 时间

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>

  输出: