main.js 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. /* let a = {
  2. name: 'Nikki',
  3. surname: 'Tikki',
  4. sex: 'male'
  5. }
  6. let b = {
  7. name: 'Nik',
  8. surname: 'Tikki',
  9. fathername: 'Anonovich'
  10. }
  11. let c = {
  12. name: 'Petro',
  13. surname: 'Tikki',
  14. age: 10
  15. } */
  16. /* debugger; */
  17. //first attemps to find key)))
  18. /* let arrayofKeys = ['sex','fathername', 'age'];
  19. for(let key in a){
  20. for(let i=0; i<arrayofKeys.length; i++){
  21. if(key == arrayofKeys[i]){
  22. alert(key)
  23. }
  24. }
  25. } */
  26. //how to find key in object, maybe variant with entries better than that
  27. /* function findFieldsinObject (obj,fieldForSearch){
  28. for(let key in obj){
  29. if(key == fieldForSearch){
  30. alert(`Object contains this field ${key}`);
  31. }
  32. }
  33. }
  34. */
  35. /* findFieldsinObject(a,'sex'); */
  36. /* let persons = [a,b,c]; */
  37. /* console.log(persons); */
  38. //show all persons like obj
  39. /* for(let i=0; i<persons.length; i++){
  40. console.log(persons[i]);
  41. }
  42. //show name and surname of persons
  43. for(let i=0; i<persons.length; i++){
  44. console.log(persons[i].name + ' ' + persons[i].surname);
  45. } */
  46. /* debugger */;
  47. //show all keys and values of all objects
  48. /* for (let i = 0; i<persons.length; i++){
  49. for(let [key,value]of Object.entries(persons[i])){
  50. console.log(`${key} ${value}`)
  51. }
  52. } */
  53. //attemps to push all keys from all object to one arr
  54. /* for (let i = 0; i<persons.length; i++){
  55. let keysarr = [];
  56. for(let [key,value]of Object.entries(persons[i])){
  57. console.log(`${key} ${value}`)
  58. keysarr.push(key);
  59. }
  60. console.log(keysarr);
  61. }
  62. */
  63. /* let arrOfKeys = [];
  64. arrOfKeys.push(key);
  65. console.log(arrOfKeys); */
  66. //add fathername
  67. /* function addFieldInObject(obj){
  68. obj["fathername"] = prompt("input fathername", "");
  69. if(obj["fathername"] == null){
  70. obj["fathername"] = "";
  71. }
  72. alert("fathername add");
  73. }
  74. addFieldInObject(a);
  75. addFieldInObject(b);
  76. addFieldInObject(c);
  77. //transform to json
  78. let jsonPersons = JSON.stringify(persons);
  79. console.log(jsonPersons); */
  80. /* var str = "<table border='1'>"
  81. for (let i=0;i<persons.length;i++){
  82. str += `<tr><td>${i}</td><td>${persons[i].name}</td> <td>${persons[i].surname}</td><td>${persons[i].fathername}</td><td>${persons[i].age}</td><td>${persons[i].sex}</td></tr>`
  83. }
  84. str += "</table>"
  85. document.write(str) */
  86. //destructuring
  87. /* let arr = [1,2,3,4,5, "a", "b", "c"];
  88. let [odd1,even1,odd2,even2,odd3,...charters] = arr;
  89. let arr1 = [1,"abc"];
  90. let [number,[s1='',s2='',s3='']] = arr1;
  91. let obj = {name: 'Ivan',
  92. surname: 'Petrov',
  93. children: [{name: 'Maria'}, {name: 'Nikolay'}]}
  94. let {name,surname,children:[name1,name2]} = obj;
  95. let arr2 = [1,2,3,4,5,6,7,10];
  96. const {length} = arr2;
  97. const [a,b,...numarr] = arr2;
  98. */