Article From:https://segmentfault.com/q/1010000011115701
Question:

Every object here corresponds to a Li (product), and a object contains three object.

I want to take out the value in object and how to get it

$('li._oBrandList').each(function(){
            var oBrandLi = $(this).attr('value');
            $.ajax({
                type:'POST',
                url:'{:U("Brand/index")}',
                async:true,
                data:{store_id:oBrandLi},
                dataType:'json',
                success:function(data){
                    console.log(data)
                }
            })
        })

Answer 0:
        for(var key in obj){
            var o = obj[key];
            for(var k in o)
                console.log(o[k]);
        }

Does that mean it?

Answer 1:
for(var i in data){
    console.log(data[i])
}

Answer 2:

for(var key in data){
console.log(data[key])
}

Answer 3:

Two methods commonly used for object value
var a = {

    key1:{
         key2:value
        }
    }
  1. a.key1.key2

  2. a[key1][key2]

Answer 4:

Nested cycle

      data.forEach(function (item,index){
        for(var key in item){
            console.log(item[key].goods_commonid);
            console.log(item[key].goods_image);
            console.log(item[key].good_url);
        }
      });

I simulated one of your data, I wonder if it is the following type:

    var data = [
      {
          0:{
              goods_commonid:'2015',
              goods_image:'asdasdsad',
              good_url:'asdasdsad'
          },
          2:{
              goods_commonid:'2015',
              goods_image:'asdasdsad',
              good_url:'asdasdsad'
          },
          2:{
              goods_commonid:'2015',
              goods_image:'asdasdsad',
              good_url:'asdasdsad'
          },
      }  ,
      {
          0:{
              goods_commonid:'2015',
              goods_image:'asdasdsad',
              good_url:'asdasdsad'
          },
          2:{
              goods_commonid:'2015',
              goods_image:'asdasdsad',
              good_url:'asdasdsad'
          },
          2:{
              goods_commonid:'2015',
              goods_image:'asdasdsad',
              good_url:'asdasdsad'
          },
      }  
    ];

Answer 5:

Use $.each to iterate over the values you want to get, for example, obj contains what you want to get:

$.each(obj,function(i,item){
     console.log(i)  //iIs your content index value obtained in the corresponding traversalConsole.log (item) //item is the content that corresponds to traversal.});

Similar Posts:

Leave a Reply

Your email address will not be published. Required fields are marked *