• for in 的使用


    
    

    data1=[
          {id:10001,icon:"icon/1.png",name:"计算机",price:1},
          {id:10002,icon:"icon/2.png",name:"服务器",price:112},
          {id:10003,icon:"icon/3.png",name:"监控",price:10},
          {id:10004,icon:"icon/4.png",name:"地动仪",price:23},
          {id:10005,icon:"icon/5.png",name:"丰收器",price:445},
          {id:10006,icon:"icon/6.png",name:"光纤仪",price:15},
          ];

          for(var key in data1[0]){
        //这里的key是键  data1[0][key]就是键下面的值   for in 循环就是键值循环遍历
            console.log(key);
          }
    //这里的data1直接写 就是数组,data[0] 就是数组下的对象了
    //如果是数组的话  就是显示的对应数组的下标 0 1 2 3 4 5 6  键值对形式的
          for(var key in data1){
            console.log(key);
          } 
     
  • 相关阅读:
    Python day thirteen
    Python day twelve
    Python day eleven
    Python day ten
    Python day nine
    Python day eight
    Python day seven
    Python day six
    Python day five
    Python day four
  • 原文地址:https://www.cnblogs.com/xiaowie/p/13475558.html
Copyright © 2020-2023  润新知