I have successfully assign 2 columns in a row, started from the number 9th element of array:
function format(d) {
let obj = String(d).split(',').slice(9);
var tbl='', res='';
obj.forEach(function(item, index) {
index % 2 === 0 ? game = item : value = item;
index % 2 !== 0 ? res += '<tr><td>' + game + '</td><td>' + value + '</td></tr>' : '';
});
tbl = '<table class="w-100 table-sm nowrap table-bordered">';
tbl += '<thead><tr><th>A</th><th>B</th><th>C</th></tr></thead>';
tbl += '<tbody>' + res + '</tbody>';
tbl += '</table>';
return tbl;
}
However, I failed to use the same method to assign for 3 columns in a row. How do I use the % operator to design the 3 columns in a row?
I get the idea from andrew:
function format(d) {
let obj = String(d).split(',').slice(9);
var tbl='', res='', value='', value2='';
obj.forEach(function(item, index) {
index % 3 === 0 ? game = '<td>' + item + '</td>' : value2 = '<td>' + item + '</td>';
index % 3 === 1 ? value = '<td>' + item + '</td>' : '';
index % 3 === 2 ? res += '<tr>' + game + value + value2 + '</tr>' : '';
});
tbl = '<table class="w-100 table-sm nowrap table-bordered">';
tbl += '<thead><tr><th>A</th><th>B</th><th>C</th></tr></thead>';
tbl += '<tbody>' + res + '</tbody>';
tbl += '</table>';
return tbl;
}