var length = document.getElementById('envTable').rows.length; var list = []; for (var i = 1; i < length; i++) { var key = document.getElementById('envTable').rows[i].cells[0].innerHTML; var value = document.getElementById('envTable').rows[i].cells[1].innerHTML; list.push({ key: key, value: value }) } let data = JSON.stringify(list);