close

<script src="js/jquery-1.12.3.min.js"></script>

    <script src="js/bootstrap.min.js"></script>

   

    <script>

    $(function(){

      

       var names = ["Jack","Tom","Mary","Fiona"];

       $.each(names,function(idx,value){console.log("陣列:"+value)})

      

      

      

       var emp = {"name":"Jack","salary":32000,"workYears":2};

       $.each(emp,function(keys,value){console.log("物件:"+keys+":"+value)})

      

       var emps = [{"name":"Jack","salary":32000,"workYears":2},

                   {"name":"Mary","salary":42000,"workYears":5},

                   {"name":"Tom","salary":52000,"workYears":7}];

      

       $.each(emps,function(index,values){

           //取出陣列中的一個個物件:[{}{}{}]→{}{}{}

           console.log("陣列中有物件"+values.name+":"+values.salary+":"+values.workYears)

       })

      

       $.each(emps,function(index,valuess){

           //取出陣列中的一個個物件:[{}{}{}]→{}{}{}

           $.each(valuess,function(keys,value){console.log("陣列中有物件2"+keys+":"+value)})

          

       })

   

      

       var data = {

                emps: [{ name: "Jack", age: 29, contact: {home:"02-12345678",cell:"0911222333"}},

                      { name: "Mary", age: 35, contact: { home: "02-33116745", cell: "0932112654" } },

                      { name: "Tom", age: 26, contact: { home: "02-54346666", cell: "0955832123" } }]

            };

       //data--{}

       //emps--[]

       $.each(data,function(name,values){

           //進入data中,有一個物件emps[]emps裡面有三個物件{},也就是[{},{},{}]

           //接下來從陣列中取出一個個物件

           $.each(values,function(idx,value){

              //value就是一個個物件{}{}{}

              console.log(value.name)

              console.log(value.age)

              console.log(value.contact.home)

              console.log(value.contact.cell)

           })

          

       })

 

 

 

       $.each(data.emps, function(index, value) {

              console.log(value.name)

              console.log(value.age)

              console.log(value.contact.home)

              console.log(value.contact.cell)

           })

 

       })

    </script>

arrow
arrow
    全站熱搜
    創作者介紹
    創作者 乙方 的頭像
    乙方

    學習筆記專區

    乙方 發表在 痞客邦 留言(0) 人氣()