var a = {
name: "Ivan",
surname: "Ivanov",
}
var b = {
name: "Petr",
surname: "Petrov",
}
var c = {
name: "Alex",
surname: "Sidarov",
}
a.age = 20;
b.fathername = "Nikolai";
c.sex = "male";
var persons = [a,b,c,
{
name: "pasha",
surname: "efimenko",
age: 22
}
]
document.write("
");
document.write("");
for (var i = 0; i < persons.length - 2; i++) {
var br;
br = false;
var key = Object.keys(persons[i]);
for (var j = 0; j < persons.length; j++) {
var keyy = Object.keys(persons[j]);
if(key[i] !== keyy[i]) // Проверяю совпадает ли ключ объкта с ключами остальных, если нет то заголовок не выводится
br = true;
}
if(br)
document.write(" | ");
else{
document.write(" | ");
$("th:nth-of-type(" + (i + 1) + ")").html(key[i]);
}
}
document.write("
");
for (var i = 0; i < persons.length; i++) {
var key = Object.keys(persons[i]);
if(!(i % 2))
document.write("");
else
document.write("
");
for (var c = 0; c < key.length; c++) {
document.write(" | ");
$("tr:nth-of-type("+ (i + 2) +") td:nth-of-type("+ (c + 1) +")").html(persons[i][key[c]]);
}
document.write("
");
}
document.write("
");