const tables = document.querySelectorAll('селектор таблиц');
for (const table of tables) {
const labels = Array.prototype.map.call(
table.querySelectorAll('thead th'),
th => th.innerText
);
for (const tbody of table.tBodies) {
for (const tr of tbody.rows) {
for (let i = 0; i < tr.cells.length; i++) {
tr.cells[i].setAttribute('data-label', labels[i]);
}
}
}
}
// или
tables.forEach(table => {
table.querySelectorAll('tbody td').forEach(function(td) {
td.dataset.label = this[td.cellIndex];
}, Array.from(table.tHead.rows[0].cells, th => th.textContent));
});