There seems to be an issue with an object structure like the following:
let clients = [{
"id": 1,
"first_name": "Felipe",
"last_name": "Aiken",
"email": "<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="d6b0b7bfbdb3b8e696e5e0e6f8b5b8">[email protected]</a>",
"gender": "Male",
"ip_address": "13.189.73.39"
}, {
"id": 2,
"first_name": "Renell",
"last_name": "Andreone",
"email": "<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="493b28272d3b2c26272c780921203a3d283d3a672a2624">[email protected]</a>",
"gender": "Female",
"ip_address": "196.153.244.124"
}];
If you try using it in a forEach loop as shown below:
clients.forEach(function(client) {
console.log(client);
let tbody = document.querySelector('tbody');
let newObj = {
'name': 'client.first_name'
};
tbody.innerHTML = tbody.innerHTML + '\
<tr>\
<td>' + client.id + '</td>\
<td>' + client.first_name + '</td>\
<td>' + client.last_name + '</td>\
<td>' + client.email + '</td>\
<td>' + client.gender + '</td>\
<td><button onclick="setClientInfo(' + (newObj) + ')" class="btn btn-primary">View</td>\
</tr>\
';
});
Upon clicking the "View" button for any item, an "Unexpected error" message shows up in the console referencing this code snippet:
setClientInfo([object Object])
The simple setClientInfo function is defined as follows:
function setClientInfo(client) {
console.log(client);
}
Any assistance on this matter would be highly appreciated.
Cheers!