main.js 771 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  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. str += "<tr>"
  27. var key = Object.keys(persons[i]);
  28. for (var c = 0; c < key.length; c++) {
  29. if(c < 3)
  30. str += "<td>" + key[c] + ": " + persons[i][key[c]] + "</td>";
  31. if(c >= 3 && key[c] in persons[i])
  32. str += "<td>" + key[c] + ": " + persons[i][key[c]] + "</td>";
  33. }
  34. str += "</tr>"
  35. }
  36. str += "</table>";
  37. document.write(str);