123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405 |
- <!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 = {
- // name: "Andrey",
- // surname: "Petroff"
- // }
- // let b = {
- // name: "Anton",
- // surname: "Nikitin"
- // }
- // let c = {
- // name: "Artem",
- // surname: "Kozyr"
- // }
- // -------------------different fields
- // let a = {
- // name: "Andrey,
- // surname: "Petroff",
- // age: "100",
- // fathername: "Akakiyovich",
- // sex: "Male"
- // }
- // let b = {
- // name: "Anton",
- // surname: "Nikitin",
- // age: "23",
- // fathername: "Ronaldovich",
- // }
- // let c = {
- // name: "Artem",
- // surname: "Kozyr",
- // fathername: "Messiyovich"
- // }
- // -------------------fields check
- // let a = {
- // name: "Andrey",
- // surname: "Petroff",
- // sex: "Male",
- // age: "100",
- // fathername: "Akakiyovich",
- // };
- // let b = {
- // name: "Anton",
- // surname: "Nikitin",
- // age: "23",
- // fathername: "Ronaldovich",
- // };
- // let c = {
- // name: "Artem",
- // surname: "Kozyr",
- // fathername: "Messiyovich",
- // };
- // if ("age" in a) {
- // alert(a.age);
- // } if ("sex" in a){
- // alert(a.sex);
- // } if ("age" in b) {
- // alert(b.age);
- // } if ("sex" in b){
- // alert(b.sex);
- // } if ("age" in c) {
- // alert(c.age);
- // } if ("sex" in c){
- // alert(c.sex);
- // }
- // -------------------array of persons
- // var persons = [
- // (a = {
- // name: "Andrey",
- // surname: "Petroff",
- // sex: "Male",
- // age: "100",
- // fathername: "Akakiyovich",
- // }),
- // (b = {
- // name: "Anton",
- // surname: "Nikitin",
- // age: "23",
- // fathername: "Ronaldovich",
- // }),
- // (c = {
- // name: "Artem",
- // surname: "Kozyr",
- // fathername: "Messiyovich",
- // }),
- // (d = {
- // "name": "Illia",
- // "surname": "Kozyr",
- // "fathername": "Sergeevych",
- // }),
- // ];
- // -------------------loop of persons
- // var persons = [
- // (a = {
- // name: "Andrey",
- // surname: "Petroff",
- // sex: "Male",
- // age: "100",
- // fathername: "Akakiyovich",
- // }),
- // (b = {
- // name: "Anton",
- // surname: "Nikitin",
- // age: "23",
- // fathername: "Ronaldovich",
- // }),
- // (c = {
- // name: "Artem",
- // surname: "Kozyr",
- // fathername: "Messiyovich",
- // }),
- // (d = {
- // "name": "Illia",
- // "surname": "Kozyr",
- // "fathername": "Sergeevych",
- // }),
- // ];
- // var index;
- // for (index = 0; index < persons.length; ++index) {
- // console.log(persons[index])
- // }
- // -------------------loop of name and surname
- // var persons = [
- // (a = {
- // name: "Andrey",
- // surname: "Petroff",
- // sex: "Male",
- // age: "100",
- // fathername: "Akakiyovich",
- // }),
- // (b = {
- // name: "Anton",
- // surname: "Nikitin",
- // age: "23",
- // fathername: "Ronaldovich",
- // }),
- // (c = {
- // name: "Artem",
- // surname: "Kozyr",
- // fathername: "Messiyovich",
- // }),
- // (d = {
- // "name": "Illia",
- // "surname": "Kozyr",
- // "fathername": "Sergeevych",
- // }),
- // ];
- // var index;
- // for (index = 0; index < persons.length; ++index) {
- // console.log(persons[index].name + " " + persons[index].surname);
- // }
- // -------------------loop of loop of values
- // var persons = [
- // (a = {
- // name: "Andrey",
- // surname: "Petroff",
- // sex: "Male",
- // age: "100",
- // fathername: "Akakiyovich",
- // }),
- // (b = {
- // name: "Anton",
- // surname: "Nikitin",
- // age: "23",
- // fathername: "Ronaldovich",
- // }),
- // (c = {
- // name: "Artem",
- // surname: "Kozyr",
- // fathername: "Messiyovich",
- // }),
- // (d = {
- // name: "Illia",
- // surname: "Kozyr",
- // fathername: "Sergeevych",
- // }),
- // ];
- // for (let index = 0; index < persons.length; index++) {
- // for (let key in persons[index]) {
- // console.log(persons[index][key]);
- // }
- // }
- // -------------------fullName
- // var persons = [
- // (a = {
- // name: "Andrey",
- // surname: "Petroff",
- // sex: "Male",
- // fathername: "Akakiyovich",
- // }),
- // (b = {
- // name: "Anton",
- // surname: "Nikitin",
- // age: "23",
- // fathername: "Ronaldovich",
- // }),
- // (c = {
- // name: "Artem",
- // surname: "Kozyr",
- // fathername: "Messiyovich",
- // }),
- // (d = {
- // name: "Illia",
- // surname: "Kozyr",
- // fathername: "Sergeevych",
- // }),
- // ];
- // for (let object of persons) {
- // if (object.name && object.surname) {
- // object.fullName = object.name + " " + object.surname;
- // }
- // }
- // console.log(persons);
- // -------------------serialize
- // console.log(JSON.stringify(persons));
- // -------------------deserialize
- // const obj = JSON.parse('d: {"name":"John", "surname": "Ivanoff", "city" : "New York"}');
- // let resoultObject = Object.assign(persons, obj);
- // console.log(resoultObject)
- // -------------------HTML
- // var persons = [
- // (a = {
- // name: "Andrey",
- // surname: "Petroff",
- // }),
- // (b = {
- // name: "Anton",
- // surname: "Nikitin",
- // }),
- // (c = {
- // name: "Artem",
- // surname: "Kozyr",
- // }),
- // (d = {
- // name: "Illia",
- // surname: "Kozyr",
- // }),
- // ];
- // var str = "<table border='1'>";
- // for (let i = 0; i < 4; i++) {
- // for (let key in persons[i]) {
- // str += `<tr><td>${[key]}</td><td>${persons[i][key]}</td></tr>`;
- // }
- // }
- // str += "</table>";
- // console.log(str);
- // document.write(str);
- // ---------------HTML optional fields
- // var persons = [
- // (a = {
- // name: "Andrey",
- // surname: "Petroff",
- // sex: "Male",
- // fathername: "Akakiyovich",
- // }),
- // (b = {
- // name: "Anton",
- // surname: "Nikitin",
- // age: "23",
- // fathername: "Ronaldovich",
- // }),
- // (c = {
- // name: "Artem",
- // surname: "Kozyr",
- // fathername: "Messiyovich",
- // }),
- // (d = {
- // name: "Illia",
- // surname: "Kozyr",
- // fathername: "Sergeevych",
- // }),
- // ];
- // var str = "<table border='1'>";
- // for (let i = 0; i < 4; i++) {
- // for (let key in persons[i]) {
- // str += `<tr><td>${[key]}</td><td>${persons[i][key]}</td></tr>`;
- // }
- // }
- // str += "</table>";
- // console.log(str);
- // document.write(str);
- // -------------------HTML tr color
- var persons = [
- (a = {
- name: "Andrey",
- surname: "Petroff",
- sex: "Male",
- fathername: "Akakiyovich",
- }),
- (b = {
- name: "Anton",
- surname: "Nikitin",
- age: "23",
- fathername: "Ronaldovich",
- }),
- (c = {
- name: "Artem",
- surname: "Kozyr",
- fathername: "Messiyovich",
- }),
- (d = {
- name: "Illia",
- surname: "Kozyr",
- fathername: "Sergeevych",
- }),
- ];
- var str = "<table border='1'>";
- for (let i = 0; i < 4; i++) {
- for (let key in persons[i]) {
- str += `<tr style="color: red;><td>${[key]}</td><td>${
- persons[i][key]
- }</td></tr>`;
- }
- }
- str += "</table>";
- console.log(str);
- document.write(str);
-
- // -------------------destruct array
- // let arr = [1,2,3,4,5, "a", "b", "c"]
- // let [odd1=1%2, even1, odd2, even2, odd3, ...arrr] = [1,2,3,4,5, "a", "b", "c"];
- //--------------------destruct string
- // let arr = [1, "abc"];
- // let [number, [s1, s2, s3]] = arr;
- // --------------------destruct 2
- // let obj = {
- // name: "Ivan",
- // surname: "Petrov",
- // children: [{ name: "Maria" }, { name: "Nikolay" }],
- // };
- // let {
- // children: [{ name: name1 }, { name: name2 }],
- // } = obj;
- // --------------------destruct 3
- let arr = [1,2,3,4, 5,6,7,10]
- let [a, b, {length = arr.length}] = arr;
- </script>
- </body>
- </html>
|