// dummy data for the example to work with:
const data = [{
'description': 'something',
'created_at': Date.now(),
'idResponder': 'TE'
}, {
'description': 'other',
'created_at': Date.now(),
'idResponder': 'TIE'
}, {
'description': 'than',
'created_at': Date.now(),
'idResponder': 'THE'
}, {
'description': 'the',
'created_at': Date.now(),
'idResponder': 'TEN'
}, {
'description': 'previous',
'created_at': Date.now(),
'idResponder': 'TE'
}, {
'description': 'entry',
'created_at': Date.now(),
'idResponder': 'TEPID'
}];
// caching a reference to the <tbody class="tbody-reply"> element:
const $tbody = $('tbody.tbody-reply');
// emptying out that element:
$('.tbody-reply').empty();
if (data != "") {
// iterating over the Array of Objects using Array.prototype.forEach():
data.forEach(
// with an Arrow function, which passes a reference to the current
// Object - of the Array of Objects - to the inner body of the
// function:
(datum) => {
// here we know the names of the properties we wish to work with, so
// we can use destructuring to assign those properties to variables
// within the function block:
let {
description,
created_at,
idResponder
} = datum,
// here we use a template literal (delimited with back-ticks) to create
// the <tr> element, and its children; we use a conditional operator
// to test if the idResponder variable is equal to 'TE', if it is we
// return a class-name of 'highlight', and if not we return an empty
// String:
tr = `<tr ${ idResponder === 'TE' ? 'class="highlight"' : '' }">
<td>${description}</td>
<td>${created_at}</td>
</tr>`
// we then append the created <tr> to the cached <tbody> element:
$tbody.append(tr);
});
} else {
$tbody.append(`
<tr>
<!-- because you didn't post your relevant HTML, or a sample of your
Array of Objects I couldn't recreate your whole <table> so I only
created two <td> elements per row; this colspan attribute will
of course need to be changed back to 6 for your own use -->
<td align="center" colspan="2">No Data Found</td>
</tr>`);
}
*,
::before,
::after {
box-sizing: border-box;
margin: 0;
padding: 0;
}
table {
border-collapse: collapse;
width: 80vw;
margin: 1em auto;
border: 3px solid #aaa;
}
th {
border-bottom: 2px solid #aaa;
}
tr.highlight {
background-color: #ffa;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<table>
<thead>
<tr>
<th>Description:</th>
<th>Created at:</th>
</tr>
</thead>
<tbody class="tbody-reply">
</tbody>
</table>