Convert Table to an Array

后端 未结 5 1349
挽巷
挽巷 2020-12-14 04:43

I have seen many posts about how to turn an array into a table, but not nearly as many going the other way. I\'m looking to take a table like this:




        
5条回答
  •  青春惊慌失措
    2020-12-14 05:11

    var table = document.getElementById( "dataTable" );
    var tableArr = [];
    for ( var i = 1; i < table.rows.length; i++ ) {
        tableArr.push({
            category: table.rows[i].cells[0].innerHTML,
            brandName: table.rows[i].cells[1].innerHTML,
            whenObtained: table.rows[i].cells[2].innerHTML,
            howObtained: table.rows[i].cells[3].innerHTML,
            howOftenWorn: table.rows[i].cells[4].innerHTML,
            whereMade: table.rows[i].cells[5].innerHTML,
            hasGraphic: table.rows[i].cells[6].innerHTML
        });
    }
    

提交回复
热议问题