JSON在控制台日志中作为[object Object]返回

TEN*_*ign 1 javascript jquery json

我有点绿色,你可以通过我的帖子历史告诉我,但我正在尝试获取JSON对象的关键值,而不是按照我的想法输出.我究竟做错了什么?

(function($){
    jQuery(document).ready(function(){
        var tableRows = [];
        var headersText = [];
        var $headers = $("th");
        var $rows = $("#table tbody tr").each(function(index) {
          $cells = $(this).find("td");
          tableRows[index] = {};
          $cells.each(function(cellIndex) {
            if(headersText[cellIndex] === undefined) {
              headersText[cellIndex] = $($headers[cellIndex]).text();
            }
            tableRows[index][headersText[cellIndex]] = $(this).text();
          });    
        });
        var tableData = {
            "tableData": tableRows
        };
        /*alert(JSON.stringify(tableData));*/

        $.each([tableData], function(key, value){
            console.log( key + ":" + value );
        });
    });
})(jQuery);
Run Code Online (Sandbox Code Playgroud)

在控制台我得到:

0:[object Object]
Run Code Online (Sandbox Code Playgroud)

而不是(例子):

0:[NAME SAMPLE-NAME]
Run Code Online (Sandbox Code Playgroud)

ade*_*neo 6

这就是当一个对象变成一个字符串,并且串起字符串和对象,该对象将被转换为一个字符串,并且一个对象的字符串表示是 [object Object]

console.log( key + ":" + value ); // you're concantenating strings and objects
Run Code Online (Sandbox Code Playgroud)

试试这个

console.log( key, value );
Run Code Online (Sandbox Code Playgroud)

作为sitenote,$.each迭代对象和数组,因此不需要将对象包装在数组中,或者将数组包装在对象中?