JSFiddle - React, Tailwind, and code Playground
by mcqueen
HTML
<table id="table-id">
<thead>
<tr>
<th>1</th>
<th>2</th>
<th>3</th>
<th>4</th>
<th>5</th>
<th>6</th>
</tr>
</thead>
</table>
JavaScript
/// result 2 5 3 1 6 4
var positions = [1, 4, 2, 0, 5, 3];
function sort(elements, positions) {
for (var i = 0; i < elements.length; i += 1) {
elements[i].parentNode.insertBefore(elements[positions[i]], elements[i]);
}
}
sort(document.getElementById('table-id').getElementsByTagName('thead')[0].getElementsByTagName('th'), positions);