123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137 |
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <meta charset="UTF-8">
- <meta http-equiv="X-UA-Compatible" content="IE=edge">
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
- <title>Document</title>
- </head>
- <body>
- <script>
- //3 persons
- let a = new Object();
- a.name = 'Petro'
- a.surname = 'Petroff'
- let b = new Object();
- b.name = 'Igor'
- b.surname = 'Igoroff'
- let c = new Object();
- c.name = 'Anton'
- c.surname = 'Antonoff'
- //different fields
- a.age = 15;
- a.fatherName = "Petrovich"
- b.car = 'Maseratti'
- b.sex = 'man'
- c.nationallity = 'tatarin'
- c.laptop = 'macbook'
- //fields check
- if ('fatherName' in a ) {
- alert(a.fatherName)
-
- }
- if ('sex' in b){
- alert(b.sex)
-
- }
- if ('laptop' in c) {
- alert(c.laptop)
- }
- //array of persons
- var persons = [];
- persons.push(a)
- persons.push(b)
- persons.push(c)
- persons.push({name : 'Archi' , surname: 'Archibalt' , sex : 'pet'})
-
-
- //loop of persons
- for (let i = 0; i < persons.length; i++) {
- console.log(persons[i]);
- }
- //loop of name and surname
- for (let i = 0; i < persons.length; i++) {
- console.log(persons[i].name + " " + persons[i].surname);
- }
- //loop of loop of values
- for (let i = 0; i < persons.length; i++) {
- for (let value of Object.values(persons[i])) {
- console.log(value);
- }
- }
- //fullName
- for (let object of persons){
- if (object.name && object.surname){
- object.fullName = object.name + " " + object.surname
- }
- }
- //serialize
- JSON.stringify(persons)
- //deserialize
- let d = '{"name" : "Artur","surname" : "Arturenko" , "fatherName": "Arturovich","age" : 34,"sex":"female"}'
- d = JSON.parse(d)
- persons[3] = d
- console.log(persons)
- //html
- let str = '<table border = "1">'
- for (let key in persons) {
- str +=
- `<tr> <td> name </td> <td> ${persons[key].name} </td> <td> surname </td> <td> ${persons[key].surname} </td> </tr> \n`;
- }
- str += "</table>"
- console.log(str)
- document.write(str)
- //HTML optional fields ++++++ //HTML tr color
- let str2 = '<table border = "1">'
- for (let keys of persons){
- str2 +=
- `<tr> <td> ${keys} </td> <td> </td></tr> \n`;
- }
-
- str2 += "</table>"
- console.log(str2)
- document.write(str2)
- //destruct array
- let arr = [1,2,3,4,5, "a", "b","c"]
- let [odd1 , even1 , odd2 , even2 , odd3 , ...letters] = arr
- //destruct string
- let arr2 = [1, "abc"]
- let [number, [s1, s2, s3]] = arr2
-
- // destruct 2
- let obj = {name: 'Ivan',
- surname: 'Petrov',
- children: [{name: 'Maria'}, {name: 'Nikolay'}]
- }
- let {
- children: [{ name: name1 }, { name: name2 }],
- } = obj;
- //destruct 3
- // let arr3 = [1,2,3,4, 5,6,7,10]
- // let [a ,b , {length = arr3.length}] = arr
- </script>
- </body>
- </html>
|