function appendCells(row, item, columns) { columns.forEach(column => { const cell = document.createElement('td'); cell.textContent = item[column]; row.appendChild(cell); }); } document.getElementById('fetchData').addEventListener('click', function () { // ... (其它代碼不變) // Handle first API data datas[0][0].json_extract.forEach(item => { const row = document.createElement('tr'); appendCells(row, item, ['ACT_DATE', 'CASE_STATUS', 'CLOSE_TMR_NAME', 'TASK_NAME']); tableBody.appendChild(row); }); // Handle second and third API data [...datas[1], ...datas[2]].forEach(item => { const row = document.createElement('tr'); appendCells(row, item, ['kindtext', 'insno', 'acceptdate', 'processingstatus']); tableBody.appendChild(row); }); // Handle fourth and fifth API data [...datas[3], ...datas[4]].forEach(item => { const row = document.createElement('tr'); appendCells(row, item, ['被保人id', '保單號碼', '被保人姓名']); tableBody.appendChild(row); }); // ... (其它代碼不變) });