Tungusv,
<!DOCTYPE HTML>
<html>
<head>
<title></title>
<meta charset="utf-8">
<style type="text/css">
td{
height: 22px; width: 80px; text-align: center;
}
</style>
</head>
<body >
<script>
function createTable(row, col, parent, masColor)
{
var table = document.createElement('table'), arr = [];
for (var i=0; i<row; i++) {
var tr = table.insertRow(i); arr[i] = [];
for (var j=0; j< col; j++) {
var td = tr.insertCell(j)
var color = masColor ? masColor[i][j] : ("000000" + (Math.random() * 16777215 | 0).toString(16)).slice(-6);
td.style.backgroundColor = "#" + color;
td.textContent = parseInt(color, 16);
arr[i].push(color)
}
}
parent.appendChild(table)
return arr
}
var body = document.body;
var mas = createTable(3, 8, body);
console.log(mas);
var new_mas = mas.map(function(ar) {
return ar.sort(function(a,b) {
return parseInt(a, 16) - parseInt(b, 16)
})
})
console.log(new_mas);
createTable(3, 8, body, new_mas);
</script>
</body>
</html>