index.html 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta http-equiv="X-UA-Compatible" content="IE=edge">
  6. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  7. <title>Document</title>
  8. </head>
  9. <body>
  10. <script>
  11. //3 persons
  12. let a = new Object();
  13. a.name = 'Petro'
  14. a.surname = 'Petroff'
  15. let b = new Object();
  16. b.name = 'Igor'
  17. b.surname = 'Igoroff'
  18. let c = new Object();
  19. c.name = 'Anton'
  20. c.surname = 'Antonoff'
  21. //different fields
  22. a.age = 15;
  23. a.fatherName = "Petrovich"
  24. b.car = 'Maseratti'
  25. b.sex = 'man'
  26. c.nationallity = 'tatarin'
  27. c.laptop = 'macbook'
  28. //fields check
  29. if ('fatherName' in a ) {
  30. alert(a.fatherName)
  31. }
  32. if ('sex' in b){
  33. alert(b.sex)
  34. }
  35. if ('laptop' in c) {
  36. alert(c.laptop)
  37. }
  38. //array of persons
  39. var persons = [];
  40. persons.push(a)
  41. persons.push(b)
  42. persons.push(c)
  43. persons.push({name : 'Archi' , surname: 'Archibalt' , sex : 'pet'})
  44. //loop of persons
  45. for (let i = 0; i < persons.length; i++) {
  46. console.log(persons[i]);
  47. }
  48. //loop of name and surname
  49. for (let i = 0; i < persons.length; i++) {
  50. console.log(persons[i].name + " " + persons[i].surname);
  51. }
  52. //loop of loop of values
  53. for (let i = 0; i < persons.length; i++) {
  54. for (let value of Object.values(persons[i])) {
  55. console.log(value);
  56. }
  57. }
  58. //fullName
  59. for (let object of persons){
  60. if (object.name && object.surname){
  61. object.fullName = object.name + " " + object.surname
  62. }
  63. }
  64. //serialize
  65. JSON.stringify(persons)
  66. //deserialize
  67. let d = '{"name" : "Artur","surname" : "Arturenko" , "fatherName": "Arturovich","age" : 34,"sex":"female"}'
  68. d = JSON.parse(d)
  69. persons[3] = d
  70. console.log(persons)
  71. //html
  72. let str = '<table border = "1">'
  73. for (let key in persons) {
  74. str +=
  75. `<tr> <td> name </td> <td> ${persons[key].name} </td> <td> surname </td> <td> ${persons[key].surname} </td> </tr> \n`;
  76. }
  77. str += "</table>"
  78. console.log(str)
  79. document.write(str)
  80. //HTML optional fields ++++++ //HTML tr color
  81. let str2 = '<table border = "1">'
  82. for (let keys of persons){
  83. str2 +=
  84. `<tr> <td> ${keys} </td> <td> </td></tr> \n`;
  85. }
  86. str2 += "</table>"
  87. console.log(str2)
  88. document.write(str2)
  89. //destruct array
  90. let arr = [1,2,3,4,5, "a", "b","c"]
  91. let [odd1 , even1 , odd2 , even2 , odd3 , ...letters] = arr
  92. //destruct string
  93. let arr2 = [1, "abc"]
  94. let [number, [s1, s2, s3]] = arr2
  95. // destruct 2
  96. let obj = {name: 'Ivan',
  97. surname: 'Petrov',
  98. children: [{name: 'Maria'}, {name: 'Nikolay'}]
  99. }
  100. let {
  101. children: [{ name: name1 }, { name: name2 }],
  102. } = obj;
  103. //destruct 3
  104. // let arr3 = [1,2,3,4, 5,6,7,10]
  105. // let [a ,b , {length = arr3.length}] = arr
  106. </script>
  107. </body>
  108. </html>