/* 3 persons */ let a = { name: 'Andriy', surname: 'Yarmolenko' } let b = { name: 'Oleksandr', surname: 'Zinchenko' } let c = { name: 'Vitaliy', surname: 'Mykolenko' } /* different fields */ a.age = '32', a.nationality = 'Ukrainian', a.club = 'West Ham United' b.age = '25', b.nationality = 'Ukrainian', b.club = 'Manchester City' c.age = '23', c.nationality = 'Ukrainian', c.club = 'Everton' /* fields check */ if ('nationality' in a, b, c) { alert(a.surname + ' ' + a.name + ' ' + a.nationality + '\n' + b.surname + ' ' + b.name + ' ' + b.nationality + '\n' + c.surname + ' ' + c.name + ' ' + c.nationality) } /* array of persons */ let persons = [] persons.push(a, b, c) persons.push({name: 'Ruslan', surname: 'Malynovskiy', age: '29', nationality: 'Ukrainian', club: 'Atalanta'}) /* 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 key in persons[i]) { console.log(persons[i][key]) } } /* fullName */ for (let newObject of persons) { if (newObject.name && newObject.surname) { newObject.fullName = newObject.name + ' ' + newObject.surname } } /* serialize */ JSON.stringify(persons) /* deserialize */ let d = JSON.parse('{"name" : "Andriy", "surname" : "Lunin", "age" : "23", "nationality" : "Ukrainian", "club" : "Real Madrid"}') persons.push(d) /* HTML */ var str = "" for (let i = 0; i < persons.length; i++) { str += `` } str += "
${persons[i].name}${persons[i].surname}
" console.log(str) document.write(str) /* HTML optional fields */ var 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 tr color */ var 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) /* destruct array */ let arr = [1,2,3,4,5, "a", "b", "c"] let [odd1, even1, odd2, even2, odd3, ...abc] = 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 {0:a, 1:b, length} = arr3