When I pass an array of objects as arguments to a function in script, I don't face any problem. But, problem occurs when I try to do the same thing while dynamically rendering some html. I get the following error - "Uncaught SyntaxError: Unexpected identifier". To be a little bit more specific, error occurs when I click rendered bottun I get "rend2([object Object],[object Object]) in my console"
const arri = [obj, obj2];
function rend(data) {
console.log(data);
let html;
let content = document.getElementById('my-list');
html = '<button onclick="rend2(' + data + ')">click</button>';
content.insertAdjacentHTML('beforeend', html);
console.log('obj', data);
}
function rend2(obj) {
console.log('obj', obj);
}