-
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathscripts.js
More file actions
28 lines (21 loc) · 650 Bytes
/
scripts.js
File metadata and controls
28 lines (21 loc) · 650 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
//let table = document.getElementById("table");
let theads = document.getElementsByTagName("th");
let theadsLength = theads.length;
let tds = document.getElementsByTagName("td");
let tdsLength = tds.length;
let tableData = [];
let resultText = document.getElementById("result");
let iThRow;
let head;
let obj = {};
for (let i = 0; i < tdsLength; i++) {
iThRow = tds[i].innerText;
head = theads[i % theadsLength].innerText;
console.log(head, iThRow);
obj[head] = iThRow;
if( (i+1) % theadsLength === 0){
tableData.push(obj);
obj = {};
}
}
resultText.textContent = `Result = ${JSON.stringify(tableData)}`;