index.html 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405
  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 = {
  13. // name: "Andrey",
  14. // surname: "Petroff"
  15. // }
  16. // let b = {
  17. // name: "Anton",
  18. // surname: "Nikitin"
  19. // }
  20. // let c = {
  21. // name: "Artem",
  22. // surname: "Kozyr"
  23. // }
  24. // -------------------different fields
  25. // let a = {
  26. // name: "Andrey,
  27. // surname: "Petroff",
  28. // age: "100",
  29. // fathername: "Akakiyovich",
  30. // sex: "Male"
  31. // }
  32. // let b = {
  33. // name: "Anton",
  34. // surname: "Nikitin",
  35. // age: "23",
  36. // fathername: "Ronaldovich",
  37. // }
  38. // let c = {
  39. // name: "Artem",
  40. // surname: "Kozyr",
  41. // fathername: "Messiyovich"
  42. // }
  43. // -------------------fields check
  44. // let a = {
  45. // name: "Andrey",
  46. // surname: "Petroff",
  47. // sex: "Male",
  48. // age: "100",
  49. // fathername: "Akakiyovich",
  50. // };
  51. // let b = {
  52. // name: "Anton",
  53. // surname: "Nikitin",
  54. // age: "23",
  55. // fathername: "Ronaldovich",
  56. // };
  57. // let c = {
  58. // name: "Artem",
  59. // surname: "Kozyr",
  60. // fathername: "Messiyovich",
  61. // };
  62. // if ("age" in a) {
  63. // alert(a.age);
  64. // } if ("sex" in a){
  65. // alert(a.sex);
  66. // } if ("age" in b) {
  67. // alert(b.age);
  68. // } if ("sex" in b){
  69. // alert(b.sex);
  70. // } if ("age" in c) {
  71. // alert(c.age);
  72. // } if ("sex" in c){
  73. // alert(c.sex);
  74. // }
  75. // -------------------array of persons
  76. // var persons = [
  77. // (a = {
  78. // name: "Andrey",
  79. // surname: "Petroff",
  80. // sex: "Male",
  81. // age: "100",
  82. // fathername: "Akakiyovich",
  83. // }),
  84. // (b = {
  85. // name: "Anton",
  86. // surname: "Nikitin",
  87. // age: "23",
  88. // fathername: "Ronaldovich",
  89. // }),
  90. // (c = {
  91. // name: "Artem",
  92. // surname: "Kozyr",
  93. // fathername: "Messiyovich",
  94. // }),
  95. // (d = {
  96. // "name": "Illia",
  97. // "surname": "Kozyr",
  98. // "fathername": "Sergeevych",
  99. // }),
  100. // ];
  101. // -------------------loop of persons
  102. // var persons = [
  103. // (a = {
  104. // name: "Andrey",
  105. // surname: "Petroff",
  106. // sex: "Male",
  107. // age: "100",
  108. // fathername: "Akakiyovich",
  109. // }),
  110. // (b = {
  111. // name: "Anton",
  112. // surname: "Nikitin",
  113. // age: "23",
  114. // fathername: "Ronaldovich",
  115. // }),
  116. // (c = {
  117. // name: "Artem",
  118. // surname: "Kozyr",
  119. // fathername: "Messiyovich",
  120. // }),
  121. // (d = {
  122. // "name": "Illia",
  123. // "surname": "Kozyr",
  124. // "fathername": "Sergeevych",
  125. // }),
  126. // ];
  127. // var index;
  128. // for (index = 0; index < persons.length; ++index) {
  129. // console.log(persons[index])
  130. // }
  131. // -------------------loop of name and surname
  132. // var persons = [
  133. // (a = {
  134. // name: "Andrey",
  135. // surname: "Petroff",
  136. // sex: "Male",
  137. // age: "100",
  138. // fathername: "Akakiyovich",
  139. // }),
  140. // (b = {
  141. // name: "Anton",
  142. // surname: "Nikitin",
  143. // age: "23",
  144. // fathername: "Ronaldovich",
  145. // }),
  146. // (c = {
  147. // name: "Artem",
  148. // surname: "Kozyr",
  149. // fathername: "Messiyovich",
  150. // }),
  151. // (d = {
  152. // "name": "Illia",
  153. // "surname": "Kozyr",
  154. // "fathername": "Sergeevych",
  155. // }),
  156. // ];
  157. // var index;
  158. // for (index = 0; index < persons.length; ++index) {
  159. // console.log(persons[index].name + " " + persons[index].surname);
  160. // }
  161. // -------------------loop of loop of values
  162. // var persons = [
  163. // (a = {
  164. // name: "Andrey",
  165. // surname: "Petroff",
  166. // sex: "Male",
  167. // age: "100",
  168. // fathername: "Akakiyovich",
  169. // }),
  170. // (b = {
  171. // name: "Anton",
  172. // surname: "Nikitin",
  173. // age: "23",
  174. // fathername: "Ronaldovich",
  175. // }),
  176. // (c = {
  177. // name: "Artem",
  178. // surname: "Kozyr",
  179. // fathername: "Messiyovich",
  180. // }),
  181. // (d = {
  182. // name: "Illia",
  183. // surname: "Kozyr",
  184. // fathername: "Sergeevych",
  185. // }),
  186. // ];
  187. // for (let index = 0; index < persons.length; index++) {
  188. // for (let key in persons[index]) {
  189. // console.log(persons[index][key]);
  190. // }
  191. // }
  192. // -------------------fullName
  193. // var persons = [
  194. // (a = {
  195. // name: "Andrey",
  196. // surname: "Petroff",
  197. // sex: "Male",
  198. // fathername: "Akakiyovich",
  199. // }),
  200. // (b = {
  201. // name: "Anton",
  202. // surname: "Nikitin",
  203. // age: "23",
  204. // fathername: "Ronaldovich",
  205. // }),
  206. // (c = {
  207. // name: "Artem",
  208. // surname: "Kozyr",
  209. // fathername: "Messiyovich",
  210. // }),
  211. // (d = {
  212. // name: "Illia",
  213. // surname: "Kozyr",
  214. // fathername: "Sergeevych",
  215. // }),
  216. // ];
  217. // for (let object of persons) {
  218. // if (object.name && object.surname) {
  219. // object.fullName = object.name + " " + object.surname;
  220. // }
  221. // }
  222. // console.log(persons);
  223. // -------------------serialize
  224. // console.log(JSON.stringify(persons));
  225. // -------------------deserialize
  226. // const obj = JSON.parse('d: {"name":"John", "surname": "Ivanoff", "city" : "New York"}');
  227. // let resoultObject = Object.assign(persons, obj);
  228. // console.log(resoultObject)
  229. // -------------------HTML
  230. // var persons = [
  231. // (a = {
  232. // name: "Andrey",
  233. // surname: "Petroff",
  234. // }),
  235. // (b = {
  236. // name: "Anton",
  237. // surname: "Nikitin",
  238. // }),
  239. // (c = {
  240. // name: "Artem",
  241. // surname: "Kozyr",
  242. // }),
  243. // (d = {
  244. // name: "Illia",
  245. // surname: "Kozyr",
  246. // }),
  247. // ];
  248. // var str = "<table border='1'>";
  249. // for (let i = 0; i < 4; i++) {
  250. // for (let key in persons[i]) {
  251. // str += `<tr><td>${[key]}</td><td>${persons[i][key]}</td></tr>`;
  252. // }
  253. // }
  254. // str += "</table>";
  255. // console.log(str);
  256. // document.write(str);
  257. // ---------------HTML optional fields
  258. // var persons = [
  259. // (a = {
  260. // name: "Andrey",
  261. // surname: "Petroff",
  262. // sex: "Male",
  263. // fathername: "Akakiyovich",
  264. // }),
  265. // (b = {
  266. // name: "Anton",
  267. // surname: "Nikitin",
  268. // age: "23",
  269. // fathername: "Ronaldovich",
  270. // }),
  271. // (c = {
  272. // name: "Artem",
  273. // surname: "Kozyr",
  274. // fathername: "Messiyovich",
  275. // }),
  276. // (d = {
  277. // name: "Illia",
  278. // surname: "Kozyr",
  279. // fathername: "Sergeevych",
  280. // }),
  281. // ];
  282. // var str = "<table border='1'>";
  283. // for (let i = 0; i < 4; i++) {
  284. // for (let key in persons[i]) {
  285. // str += `<tr><td>${[key]}</td><td>${persons[i][key]}</td></tr>`;
  286. // }
  287. // }
  288. // str += "</table>";
  289. // console.log(str);
  290. // document.write(str);
  291. // -------------------HTML tr color
  292. var persons = [
  293. (a = {
  294. name: "Andrey",
  295. surname: "Petroff",
  296. sex: "Male",
  297. fathername: "Akakiyovich",
  298. }),
  299. (b = {
  300. name: "Anton",
  301. surname: "Nikitin",
  302. age: "23",
  303. fathername: "Ronaldovich",
  304. }),
  305. (c = {
  306. name: "Artem",
  307. surname: "Kozyr",
  308. fathername: "Messiyovich",
  309. }),
  310. (d = {
  311. name: "Illia",
  312. surname: "Kozyr",
  313. fathername: "Sergeevych",
  314. }),
  315. ];
  316. var str = "<table border='1'>";
  317. for (let i = 0; i < 4; i++) {
  318. for (let key in persons[i]) {
  319. str += `<tr style="color: red;><td>${[key]}</td><td>${
  320. persons[i][key]
  321. }</td></tr>`;
  322. }
  323. }
  324. str += "</table>";
  325. console.log(str);
  326. document.write(str);
  327. // -------------------destruct array
  328. // let arr = [1,2,3,4,5, "a", "b", "c"]
  329. // let [odd1=1%2, even1, odd2, even2, odd3, ...arrr] = [1,2,3,4,5, "a", "b", "c"];
  330. //--------------------destruct string
  331. // let arr = [1, "abc"];
  332. // let [number, [s1, s2, s3]] = arr;
  333. // --------------------destruct 2
  334. // let obj = {
  335. // name: "Ivan",
  336. // surname: "Petrov",
  337. // children: [{ name: "Maria" }, { name: "Nikolay" }],
  338. // };
  339. // let {
  340. // children: [{ name: name1 }, { name: name2 }],
  341. // } = obj;
  342. // --------------------destruct 3
  343. let arr = [1,2,3,4, 5,6,7,10]
  344. let [a, b, {length = arr.length}] = arr;
  345. </script>
  346. </body>
  347. </html>