// 3 persons/////////////////////////////// var a = { name: "Ivan", surname: "Ivanov", } var b = { name: "Petr", surname: "Petrov", } var c = { name: "Stepan", surname: "Stepanov", } // different fields//////////////////////// var a = { name: "Ivan", surname: "Ivanov", sex: "male", } var b = { name: "Petr", surname: "Petrov", fathername: "Petrovich", } var c = { name: "Stepan", surname: "Stepanov", age: 33, } // fields check//////////////////////////// var a = { name: "Ivan", surname: "Ivanov", sex: "male", } var b = { name: "Petr", surname: "Petrov", fathername: "Petrovich", } var c = { name: "Stepan", surname: "Stepanov", age: 33, } if ('sex' in a) { alert("found word in a!") } if ('fathername' in b) { alert("found word in b!") } if (typeof { age: 33 } === 'object') { alert("found in c!") } // array of persons//////////////////////// var a = { name: "Ivan", surname: "Ivanov", sex: "male", } var b = { name: "Petr", surname: "Petrov", fathername: "Petrovich", } var c = { name: "Stepan", surname: "Stepanov", age: 33, } var persons = [] persons.push(a, b, c, { name: "Vasya", surname: "Vasiliev", fathername: "Vasilievich" }) console.log(persons) // loop of persons////////////////////////// var a = { name: "Ivan", surname: "Ivanov", sex: "male", } var b = { name: "Petr", surname: "Petrov", fathername: "Petrovich", } var c = { name: "Stepan", surname: "Stepanov", age: 33, } var persons = [] persons.push(a, b, c, { name: "Vasya", surname: "Vasiliev", fathername: "Vasilievich" }) for (let i = 0; i < persons.length; i++) { console.log(persons[i]); } // loop of name and surname////////////////// var a = { name: "Ivan", surname: "Ivanov", sex: "male", } var b = { name: "Petr", surname: "Petrov", fathername: "Petrovich", } var c = { name: "Stepan", surname: "Stepanov", age: 33, } var persons = [] persons.push(a, b, c, { name: "Vasya", surname: "Vasiliev", fathername: "Vasilievich" }) for (let i = 0; i < persons.length; i++) { console.log(persons[i].name, persons[i].surname); } // loop of loop of values//////////////////// var a = { name: "Ivan", surname: "Ivanov", sex: "male", } var b = { name: "Petr", surname: "Petrov", fathername: "Petrovich", } var c = { name: "Stepan", surname: "Stepanov", age: 33, } var persons = [] persons.push(a, b, c, { name: "Vasya", surname: "Vasiliev", fathername: "Vasilievich" }) for (let i = 0; i < persons.length; i++) { for (let values in persons[i]) { console.log(persons[i][values]); } } // fullName/////////////////////////////////// var a = { name: "Ivan", surname: "Ivanov", sex: "male", } var b = { name: "Petr", surname: "Petrov", fathername: "Petrovich", } var c = { name: "Stepan", surname: "Stepanov", age: 33, } var persons = [] persons.push(a, b, c, { name: "Vasya", surname: "Vasiliev", fathername: "Vasilievich" }) for (let i = 0; i < persons.length; i++) { if (persons[i].name && persons[i].surname) { persons[i].fullName = persons[i].name + " " + persons[i].surname; } else if (persons[i].fathername) { persons[i].fullName = persons[i].name + " " + persons[i].fathername + " " + persons[i].surname; } console.log(persons[i].fullName) } // serialize////////////////////////////////// JSON.stringify(persons) // deserialize//////////////////////////////// persons.push(JSON.parse('{"name":"Steve","surname":"Jobs","sex":"male"}')) console.log(persons) // HTML/////////////////////////////////////// var str = "\n" for (let i = 0; i < persons.length; i++) { console.log(persons[i]); str += `\n \n` } str += "
${persons[i].name}${persons[i].surname}
" console.log(str) document.write(str) // HTML optional fields/////////////////////// // var a = { // name: "Ivan", // surname: "Ivanov", // fathername: "Ivanovich", // sex: "male", // age: 33, // } // var b = { // name: "Petr", // surname: "Petrov", // fathername: "Petrovich", // sex: "male", // age: 33, // } // var c = { // name: "Stepan", // surname: "Stepanov", // fathername: "Stepanovich", // sex: "male", // age: 33, // } // var persons1 = [] // persons1.push(a, b, c, { // name: "Vasya", surname: "Vasiliev", fathername: "Vasilievich", sex: "male", age: 33, // }) // for (let i = 0; i < persons1.length; i++) { // console.log(persons1[i]); // } var str = "" for (let i = 0; i < persons1.length; i++) { console.log(persons1[i]); str += `` } str += "
${persons1[i].name}${persons1[i].surname} ${persons1[i].fathername}${persons1[i].age}${persons1[i].sex}
" console.log(str) document.write(str) // HTML tr color////////////////////////////// var str = "" for (let i = 0; i < persons1.length; i++) { console.log(persons1[i]); if (i % 2 === 0) { str += `` } else { str += `` } } str += "
${persons1[i].name}${persons1[i].surname} ${persons1[i].fathername}${persons1[i].age}${persons1[i].sex}
${persons1[i].name}${persons1[i].surname} ${persons1[i].fathername}${persons1[i].age}${persons1[i].sex}
" console.log(str) document.write(str) // HTML th optional///////////////////////////