123456789101112131415161718192021222324252627282930313233343536373839404142434445 |
- 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
- }
- ]
- var str = "";
- str += "<table>"
- for (var i = 0; i < persons.length; i++) {
- if(!(i % 2))
- str += "<tr style = 'background: #ccc;'>"
- else
- str += "<tr>"
- var key = Object.keys(persons[i]);
- for (var c = 0; c < key.length; c++) {
- if(c < 3)
- str += "<td>" + key[c] + ": " + persons[i][key[c]] + "</td>";
- if(c >= 3 && key[c] in persons[i])
- str += "<td>" + key[c] + ": " + persons[i][key[c]] + "</td>";
- }
- str += "</tr>"
- }
- str += "</table>";
- document.write(str);
|