main.js 852 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. var a = {
  2. name: "Ivan",
  3. surname: "Ivanov",
  4. }
  5. var b = {
  6. name: "Petr",
  7. surname: "Petrov",
  8. }
  9. var c = {
  10. name: "Alex",
  11. surname: "Sidarov",
  12. }
  13. a.age = 20;
  14. b.fathername = "Nikolai";
  15. c.sex = "male";
  16. var persons = [a,b,c,
  17. {
  18. name: "pasha",
  19. surname: "efimenko",
  20. age: 22
  21. }
  22. ]
  23. var str = "";
  24. str += "<table>"
  25. for (var i = 0; i < persons.length; i++) {
  26. if(!(i % 2))
  27. str += "<tr style = 'background: #ccc;'>"
  28. else
  29. str += "<tr>"
  30. var key = Object.keys(persons[i]);
  31. for (var c = 0; c < key.length; c++) {
  32. if(c < 3)
  33. str += "<td>" + key[c] + ": " + persons[i][key[c]] + "</td>";
  34. if(c >= 3 && key[c] in persons[i])
  35. str += "<td>" + key[c] + ": " + persons[i][key[c]] + "</td>";
  36. }
  37. str += "</tr>"
  38. }
  39. str += "</table>";
  40. document.write(str);