Quantcast
Channel: Tópicos
Viewing all articles
Browse latest Browse all 14700

Duvida construção de Array

$
0
0
Boas,
Estou a utlizar o seguinte código de forma a separar o array com o objectivo de dividir em por um grupo de 5 linhas por 2 colunas dentro de uma tabela, ou seja o array viria da seguinte forma
1 2
3 4
5 6
7 8
9 10
Código :
<script>
var orderArray = ["1","2","3","4","5","6","7","8","9","10"]
function display() {
    // get handle on div
    var container = document.getElementById('container');
    // create table element
    var table = document.createElement('table');
    var tbody = document.createElement('tbody');
    // loop array
    for (var i = 0; i < orderArray.length; i++) {
            // get inner array
            var vals = orderArray[i];
            // create tr element
            var row = document.createElement('tr');
            // loop inner array
            for (var b = 0; b < vals.length; b++) {
                    // create td element
                    var cell = document.createElement('td');
                    // set text
                    cell.textContent = vals[b];
                    // append td to tr
                    row.appendChild(cell);
            }
            //append tr to tbody
            tbody.appendChild(row);
    }
    // append tbody to table
    table.appendChild(tbody);
    // append table to container
    container.appendChild(table);
}
display();

Mas ele apenas me devolve da seguinte forma
1
2
3
4
5
6
7
8
9
10

Alguem me pode ajudar?

Viewing all articles
Browse latest Browse all 14700