<html>
<body>
<table>
<tbody id="tblBody">
</tbody>
</table>
<script>
let t = [{a:1, b:2},{a:3, b:4}]
populate(t)
function populate(t) {
let tbody = document.getElementById('tblBody')
let tableHtml = ''
t.forEach(obj => {
tableHtml += `
<tr>
<td>${obj.a}</td>
<td>${obj.b}</td>
<td>
<button onclick= "editT(${JSON.stringify(obj)})">Edit</button>
</td>
</tr>
`
});
tbody.innerHTML = tableHtml
}
const editT = (obj) => {
let parsedObj = JSON.parse(obj)
console.log(parsedObj)
}
</script>
</body>
</html>
But I am unable to set obj as a parameter of function editT(). Is there any way to set object as parameter so that each object can be edited by clicking button in a dynamic table. Actual object has many key value pairs.