使用jqueryeach()从对象获取特定值

使用jqueryeach()从对象获取特定值,jquery,Jquery,我试图用表中的一些信息填充列表。我有上面的对象,我想得到如下值: [Object, Object] 0:Object chat:"i like to say hello" id:13 user_id:1 yiinput_id:5 __proto__:Object 1:Object chat:"another chat here" id:14 user_id:1 yiinput_id:5 __proto__:Object length:2 __proto__:Array[0]

我试图用表中的一些信息填充列表。我有上面的对象,我想得到如下值:

[Object, Object]
0:Object
 chat:"i like to say hello"
 id:13
 user_id:1
 yiinput_id:5
 __proto__:Object
1:Object
 chat:"another chat here"
 id:14
 user_id:1
 yiinput_id:5
 __proto__:Object
length:2
__proto__:Array[0]

您可以直接访问
chats
数组中对象的属性,而无需另一个循环。试试这个:

$.each(resp.chats, function() {
            $.each(this, function(k, v) {
                console.log(k + ' ' + v);//this gets me all keys and values but i need specific key value
            console.log("Chat ="+ //need chat value here );
            console.log("User ID ="+ //need id value here );
            });
        });

您可以直接访问
chats
数组中对象的属性,而无需另一个循环。试试这个:

$.each(resp.chats, function() {
            $.each(this, function(k, v) {
                console.log(k + ' ' + v);//this gets me all keys and values but i need specific key value
            console.log("Chat ="+ //need chat value here );
            console.log("User ID ="+ //need id value here );
            });
        });

你可以从结构上得到它

$.each(resp.chats, function(i, chat) {
    var value = chat.chat;
    var userId = chat.user_id;

    // use the variables as required here...
    console.log(value, userId);
});

你可以从结构上得到它

$.each(resp.chats, function(i, chat) {
    var value = chat.chat;
    var userId = chat.user_id;

    // use the variables as required here...
    console.log(value, userId);
});