Created
February 14, 2020 17:41
-
-
Save radxene/9fd61539a83fdc662f1ce0cb641aa695 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
!(function() { | |
'use strict'; | |
var fruits = [ | |
{ apple: 100, pear: 23, cherry: 40 }, | |
{ apple: 400, pear: 34, cherry: 90 }, | |
{ apple: 20, pear: 60, cherry: 100 }, | |
]; | |
var header = ['яблоки', 'груши', 'вишенка']; | |
var table = document.createElement('TABLE'); | |
var thead = document.createElement('THEAD'); | |
var tbody = document.createElement('TBODY'); | |
var tr = null; | |
var i = 0; | |
tr = document.createElement('TR'); | |
for (i = 0; i < header.length; ++i) { | |
var th = document.createElement('TH'); | |
var text = document.createTextNode(header[i]); | |
th.appendChild(text); | |
tr.appendChild(th); | |
} | |
thead.appendChild(tr); | |
for (i = 0; i < fruits.length; ++i) { | |
tr = document.createElement('TR'); | |
var row = fruits[i]; | |
var keys = Object.keys(row); | |
for (var j = 0; j < keys.length; ++j) { | |
var key = keys[j]; | |
var td = document.createElement('TD'); | |
var tdText = document.createTextNode(row[key]); | |
td.appendChild(tdText); | |
tr.appendChild(td); | |
} | |
tbody.appendChild(tr); | |
} | |
document.addEventListener('DOMContentLoaded', function() { | |
table.appendChild(thead); | |
table.appendChild(tbody); | |
window.document.body.appendChild(table); | |
}); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment