I'm a little green as you can tell by my post history here, but i am trying to get the key, value for a JSON object and its not outputting as i thought it would. What am I doing wrong?
(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);
in console I'm getting:
0:[object Object]
instead of (example):
0:[NAME SAMPLE-NAME]