// 3 persons,different fields and fields check let a = { name: 'Petro', surname: 'Petrovich', "age": '30', "fathername": 'Petroff', "sex": 'male', } let b = { name: 'Ivan', surname: 'Ivanov', "age": '35', "fathername": 'Ivanovich', "sex": 'male', } let c = { name: 'Sveta', surname: 'Svetova', "age": '40', "fathername": 'Serhiivna', "sex": 'female', } if ("age" in a) { alert(a.age); } if ("fathername" in a) { alert(a.fathername); } if ("sex" in a) { alert(a.sex) } if ("age" in b) { alert(b.age); } if ("fathername" in b) { alert(b.fathername); } if ("sex" in b) { alert(b.sex) } if ("age" in c) { alert(c.age); } if ("fathername" in c) { alert(c.fathername); } if ("sex" in c) { alert(c.sex); } // array of persons let persons = [a, b, c, { name: 'Olha', surname: 'Petrova', age: '45', sex: 'female' }]; // loop of persons let output; for (output = 0; output < persons.length; ++output) { console.log(persons[output]) } // loop of name and surname let outputNameAndSurname; for (outputNameAndSurname = 0; outputNameAndSurname < persons.length; ++outputNameAndSurname) { console.log(persons[outputNameAndSurname].name + " " + persons[outputNameAndSurname].surname); }; // loop of loop of values for (let output = 0; output < persons.length; output++) { for (let key in persons[output]) { console.log(persons[output][key]); } }; // fullName for (let key of persons) { if (key.name && key.surname) { key.fullName = key.name + " " + key.surname; } } console.log(persons); // serialize JSON.stringify(arrofPersons); // deserialize let d = '{"name" : "Olha","surname" : "Petrova" ,"age" : 45,"sex":"female"}' d = JSON.parse(d) persons[3] = d console.log(persons) // HTML let str = ""; for (let i = 0; i < persons.length; i++) { for (let key in persons[i]) { str += ``; } } str += "
${[key]}${persons[i][key]}
"; console.log(str); document.write(str); // HTML optional fields let strTwo = "" for (let i = 0; i < 4; i++) { for (let key in persons[i]) { strTwo += `` } } strTwo += "
${key}${persons[i][key]}
" console.log(strTwo) document.write(strTwo) // HTML tr color let strThree = ""; for (let i = 0; i < 4; i++) { for (let key in persons[i]) { strThree += `"; console.log(strThree); document.write(strThree); // HTML th optional // 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 numberTwo = [1, 2, 3, 4, 5, 6, 7, 10]; let [a, b, { length = numberTwo.length }] = numberTwo; }