|
@@ -0,0 +1,167 @@
|
|
|
+// 3 persons //different fields //fields check
|
|
|
+
|
|
|
+let a = {
|
|
|
+ "name": "Jimmy",
|
|
|
+ "surname": "Dick",
|
|
|
+ };
|
|
|
+ a.sex = "male";
|
|
|
+ let b = {
|
|
|
+ "name": "Sara",
|
|
|
+ "surname":"Conor",
|
|
|
+ };
|
|
|
+ b.fathername = "Leonidovna"
|
|
|
+ let c = {
|
|
|
+ "name": "Stan",
|
|
|
+ "surname": "Jopa",
|
|
|
+ };
|
|
|
+ c.age = 18;
|
|
|
+ if ("sex" in a ){
|
|
|
+ alert("Sex in a")
|
|
|
+ }if ("fathername" in b ){
|
|
|
+ alert("fathername in b")
|
|
|
+ }if ("age" in c ){
|
|
|
+ alert("age in c")}
|
|
|
+
|
|
|
+ // array of persons
|
|
|
+
|
|
|
+ a = {
|
|
|
+ "name": "Jimmy",
|
|
|
+ "surname": "Dick",
|
|
|
+
|
|
|
+ },
|
|
|
+ b = {
|
|
|
+ "name": "Sara",
|
|
|
+ "surname":"Conor",
|
|
|
+
|
|
|
+ },
|
|
|
+ c = {
|
|
|
+ "name": "Stan",
|
|
|
+ "surname": "Jopa",
|
|
|
+
|
|
|
+ }
|
|
|
+ let persons = [a, b, c];
|
|
|
+ let d = {
|
|
|
+ "name":"Gregor",
|
|
|
+ "surname":"Clit",
|
|
|
+
|
|
|
+ };
|
|
|
+ persons.push(d)
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ // loop of persons
|
|
|
+
|
|
|
+ for(let i in persons){
|
|
|
+ console.log(persons[i])
|
|
|
+ };
|
|
|
+
|
|
|
+ // loop of name and surname
|
|
|
+
|
|
|
+ for( i in persons){
|
|
|
+ console.log(persons[i].name, persons[i].surname);
|
|
|
+ }
|
|
|
+
|
|
|
+ // loop of loop of values
|
|
|
+
|
|
|
+ for( i in persons){
|
|
|
+ for(values in persons[i]){
|
|
|
+ console.log(persons[i][values])}}
|
|
|
+
|
|
|
+ // fullName???
|
|
|
+
|
|
|
+ if("fathername" in a ){
|
|
|
+ persons[0].fullName = "fullName"
|
|
|
+ }else if("fathername" in a ){
|
|
|
+ persons[1].fullName = "fullName"
|
|
|
+ }else if("fathername" in a ){
|
|
|
+ persons[2].fullName = "fullName"
|
|
|
+ }else if("fathername" in a ){
|
|
|
+ persons[3].fullName = "fullName"
|
|
|
+ }
|
|
|
+
|
|
|
+ // serialize
|
|
|
+
|
|
|
+ JSON.stringify(persons)
|
|
|
+
|
|
|
+ '[{"name":"Jimmy","surname":"Dick"},{"name":"Sara","surname":"Conor"},{"name":"Stan","surname":"Jopa"},{"name":"Gregor","surname":"Clit"},{"name:"Billy","surname":"Herington"}]'
|
|
|
+
|
|
|
+ let jsPersons = JSON.stringify(persons)
|
|
|
+
|
|
|
+ // deserialize
|
|
|
+
|
|
|
+ jsPersons ='[{"name":"Jimmy","surname":"Dick"},{"name":"Sara","surname":"Conor"},{"name":"Stan","surname":"Jopa"},{"name":"Gregor","surname":"Clit"},{"name":"Bill","surname":"Didi"}]'
|
|
|
+ let objPersons = JSON.parse(jsPersons)
|
|
|
+
|
|
|
+ // HTML/ HTML optional fields/ HTML tr color
|
|
|
+
|
|
|
+ // let a = {
|
|
|
+ // "name": "Jimmy",
|
|
|
+ // "surname": "Dick",
|
|
|
+ // };
|
|
|
+ // a.sex = "male";
|
|
|
+ // let b = {
|
|
|
+ // "name": "Sara",
|
|
|
+ // "surname":"Conor",
|
|
|
+ // };
|
|
|
+ // b.fathername = "Leonidovna"
|
|
|
+ // let c = {
|
|
|
+ // "name": "Stan",
|
|
|
+ // "surname": "Jopa",
|
|
|
+ // };
|
|
|
+ // c.age = 18;
|
|
|
+ // let persons = [a, b, c];
|
|
|
+ // let d = {
|
|
|
+ // "name":"Gregor",
|
|
|
+ // "surname":"Clit",
|
|
|
+ // "fathername":"Cumguy"
|
|
|
+ // };
|
|
|
+ // persons.push(d)
|
|
|
+
|
|
|
+ let str = "<table border='1'>"
|
|
|
+ str += "<tr><th>persons</th><th>name</th><th>surname</th><th>age</th><th>fathername</th><th>sex</th></tr>"
|
|
|
+ for(let i = 0; i < persons.length; i++){
|
|
|
+ if(i % 2 == 0){
|
|
|
+ str += `<tr style='background: blue'>
|
|
|
+ <td>${i}</td>
|
|
|
+ <td>${persons[i]["name"]}</td>
|
|
|
+ <td>${persons[i]["surname"]}</td>
|
|
|
+ <td>${persons[i]["age"]}</td>
|
|
|
+ <td>${persons[i]["fathername"]}</td>
|
|
|
+ <td>${persons[i]["sex"]}</td></tr>`
|
|
|
+ }
|
|
|
+ else{
|
|
|
+ str += `<tr style='background: yellow'>
|
|
|
+ <td>${i}</td>
|
|
|
+ <td>${persons[i]["name"]}</td>
|
|
|
+ <td>${persons[i]["surname"]}</td>
|
|
|
+ <td>${persons[i]["age"]}</td>
|
|
|
+ <td>${persons[i]["fathername"]}</td>
|
|
|
+ <td>${persons[i]["sex"]}</td></tr>`
|
|
|
+ }
|
|
|
+
|
|
|
+ str += "</table>"
|
|
|
+ document.write(str)
|
|
|
+
|
|
|
+ // destruct array
|
|
|
+
|
|
|
+let arr = [1,2,3,4,5, "a", "b", "c"]
|
|
|
+let [odd1,even1,odd2,even2,odd3,...letters] = arr;
|
|
|
+
|
|
|
+// destruct string
|
|
|
+
|
|
|
+let arr1 = [1, "abc"]
|
|
|
+let [number] = arr1
|
|
|
+let [s1,s2,s3] = arr1[1]
|
|
|
+
|
|
|
+// destruct 2
|
|
|
+
|
|
|
+let obj = {name: 'Ivan',
|
|
|
+ surname: 'Petrov',
|
|
|
+ children: [{name: 'Maria'}, {name: 'Nikolay'}]}
|
|
|
+
|
|
|
+let [name1,name2] = obj.children;
|
|
|
+
|
|
|
+// destruct 3
|
|
|
+
|
|
|
+let arr2 = [1,2,3,4, 5,6,7,10]
|
|
|
+let [a,b,...length] = arr2
|