123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782 |
- // 3 persons ==============================================================================
- let personOne={
- name: '',
- surname: '',
- }
- let personTwo={
- name:'',
- surname:''
- }
- let personThree={
- name:'',
- surname:''
- }
- // different fields ==============================================================================
- let personOne={
- name: '',
- surname: '',
- age: '',
- fathername: '',
- sex: ''
- }
- let personTwo={
- name:'',
- surname:'',
- 'age': '',
- 'fathername': '',
- 'sex': ''
- }
- let personThree={
- name:'',
- surname:'',
- age:
- '',
- fathername:
- '',
- sex:
- ''
- }
- // fields check ==============================================================================
- let personOne={
- name: 'Vlad',
- surname: 'Stasenko',
- age: '27',
- fathername: 'Andriyovich',
- sex: ''
- }
- if ('sex' in personOne){
- alert(personOne.sex + ' Необязательное поле')
- }
- // либо =============================================
- if (typeof personOne.sex === 'string'){
- alert(personOne.sex + ' Необязательное поле')
- }
- let personTwo={
- name:'Kate',
- surname:'Stasenko',
- 'age': '',
- 'fathername': 'Andriivna',
- 'sex': 'woman'
- }
- if('age' in personTwo){
- alert(personTwo.age + ' Необязательное поле')
- }
- // либо =============================================
- if(typeof personTwo.age === 'string'){
- alert(personTwo.age + ' Необязательное поле')
- }
- let personThree={
- name:'Daniel',
- surname:'Deli',
- age:
- '27',
- fathername:
- '',
- sex:
- 'man'
- }
- if ('fathername' in personThree){
- alert(personThree.fathername + ' Необязательное поле')
- }
- // либо =============================================
- if(typeof personThree.fathername === 'string'){
- alert(personThree.fathername + ' Необязательное поле')
- }
- // array of persons ==============================================================================
- let persons = [
- personOne={
- name: '',
- surname: '',
- age: '',
- fathername: '',
- sex: ''
- },
- personTwo={
- name:'',
- surname:'',
- 'age': '',
- 'fathername': '',
- 'sex': ''
- },
- personThree={
- name:'',
- surname:'',
- age:
- '',
- fathername:
- '',
- sex:
- ''
- }
- ]
- // loop of persons ==============================================================================
- let persons = [
- personOne={
- name: '',
- surname: '',
- age: '',
- fathername: '',
- sex: ''
- },
- personTwo={
- name:'',
- surname:'',
- 'age': '',
- 'fathername': '',
- 'sex': ''
- },
- personThree={
- name:'',
- surname:'',
- age:
- '',
- fathername:
- '',
- sex:
- ''
- }
- ]
- for (let key in persons){
- console.log(persons[key]);
- }
- // либо =============================================
- let persons = [
- personOne={
- name: '',
- surname: '',
- age: '',
- fathername: '',
- sex: ''
- },
- personTwo={
- name:'',
- surname:'',
- 'age': '',
- 'fathername': '',
- 'sex': ''
- },
- personThree={
- name:'',
- surname:'',
- age:
- '',
- fathername:
- '',
- sex:
- ''
- }
- ]
- for (let i = 0; i<persons.length; ++i){
- console.log(persons[i]);
- }
- // loop of name and surname ==============================================================================
- let persons = [
- personOne={
- name: 'Vlad',
- surname: 'Stasenko',
- age: '',
- fathername: '',
- sex: ''
- },
- personTwo={
- name:'Kate',
- surname:'Stasenko',
- 'age': '',
- 'fathername': '',
- 'sex': ''
- },
- personThree={
- name:'Sveta',
- surname:'Stasenko',
- age:
- '',
- fathername:
- '',
- sex:
- ''
- }
- ]
- for (let key in persons){
- console.log(persons[key].name +' '+ persons[key].surname);
- }
- // loop of loop of values ==============================================================================
- let persons = [
- personOne={
- name: 'Vlad',
- surname: 'Stasenko',
- age: 27,
- fathername: 'Andriyovich',
- sex: 'man'
- },
- personTwo={
- name:'Kate',
- surname:'Stasenko',
- 'age': '27',
- 'fathername': 'Andriivna',
- 'sex': 'woman'
- },
- personThree={
- name:'Sveta',
- surname:'Stasenko',
- age:
- '48',
- fathername:
- 'Oleksiivna',
- sex:
- 'woman'
- }
- ]
- for(let i=0; i<(persons.length); i++ ){
- for(let key in persons[i]){
- console.log(persons[i][key])
- }
- }
- // fullName ==============================================================================
- let persons = [
- personOne={
- name: 'Vlad',
- surname: 'Stasenko',
- age: 27,
- fathername: 'Andriyovich',
- sex: 'man'
- },
- personTwo={
- name:'Kate',
- surname:'Stasenko',
- 'age': '27',
- 'fathername': 'Andriivna',
- 'sex': 'woman'
- },
- personThree={
- name:'Sveta',
- surname:'Stasenko',
- age:
- '48',
- fathername:
- 'Oleksiivna',
- sex:
- 'woman'
- }
- ]
- for(let i=0; i<(persons.length); i++ ){
- persons[i].fullName = (persons[i].name + ' ' + persons[i].surname + ' ' + persons[i].fathername)
- console.log(persons[i])
- }
- // serialize ==============================================================================
- let persons = [
- personOne={
- name: 'Vlad',
- surname: 'Stasenko',
- age: 27,
- fathername: 'Andriyovich',
- sex: 'man'
- },
- personTwo={
- name:'Kate',
- surname:'Stasenko',
- 'age': '27',
- 'fathername': 'Andriivna',
- 'sex': 'woman'
- },
- personThree={
- name:'Sveta',
- surname:'Stasenko',
- age:
- '48',
- fathername:
- 'Oleksiivna',
- sex:
- 'woman'
- }
- ]
- let json = JSON.stringify(persons)
- console.log(json)
- // deserialize ==============================================================================
- let persons = [
- personOne={
- name: 'Vlad',
- surname: 'Stasenko',
- age: 27,
- fathername: 'Andriyovich',
- sex: 'man'
- },
- personTwo={
- name:'Kate',
- surname:'Stasenko',
- 'age': 27,
- 'fathername': 'Andriivna',
- 'sex': 'woman'
- },
- personThree={
- name:'Sveta',
- surname:'Stasenko',
- age:
- 48,
- fathername:
- 'Oleksiivna',
- sex:
- 'woman'
- }
- ]
- let json = JSON.stringify(persons)
- let personFour = {"name": "Andrey", "surname": "Stasenko", "age": 48, "fathername": "Anatoliiovych", "sex": "man"}
- json= JSON.parse(persons.push(personFour))
- json=JSON.stringify(persons)
- console.log(persons)
- // HTML ==============================================================================
- let persons = [
- personOne={
- name: 'Vlad',
- surname: 'Stasenko',
- age: 27,
- fathername: 'Andriyovich',
- sex: 'man'
- },
- personTwo={
- name:'Kate',
- surname:'Yancheva',
- 'age': 27,
- 'fathername': 'Andriivna',
- 'sex': 'woman'
- },
- personThree={
- name:'Sveta',
- surname:'Maksimenko',
- age:
- 48,
- fathername:
- 'Oleksiivna',
- sex:
- 'woman'
- }
- ]
- let json = JSON.stringify(persons)
- let personFour = {"name": "Andrey", "surname": "Stasenko", "age": 48, "fathername": "Anatoliiovych", "sex": "man"}
- json= JSON.parse(persons.push(personFour))
- json=JSON.stringify(persons)
- var str = "<table border='1'>"
- for (let i=0;i<persons.length;i++){
- str += `<tr><td>${persons[i].name}</td><td>${persons[i].surname}</td></tr>`
- }
- str += "</table>"
- console.log(str)
- document.write(str)
- // HTML optional fields ==============================================================================
- let personFour
- let persons = [
- personOne={
- name: 'Vlad',
- surname: 'Stasenko',
- age: 27,
- fathername: 'Andriyovich',
- sex: 'man'
- },
- personTwo={
- name:'Kate',
- surname:'Yancheva',
- 'age': 27,
- 'fathername': 'Andriivna',
- 'sex': 'woman'
- },
- personThree={
- name:'Sveta',
- surname:'Maksimenko',
- age:
- 48,
- fathername:
- 'Oleksiivna',
- sex:
- 'woman'
- }
- ]
- let json = JSON.stringify(persons)
- personFour = {"name": "Andrey", "surname": "Stasenko", "age": 48, "fathername": "Anatoliiovych", "sex": "man"}
- json= JSON.parse(persons.push(personFour))
- json= JSON.stringify(persons)
- var str = "<table border='1'>"
- for(let key in persons[0]){
- str+= `<td>${key}</td>`
- }
- for (let i=0;i<persons.length;i++){
- str += `<tr><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)
- // HTML tr color ==============================================================================
- let personFour
- let persons = [
- personOne={
- name: 'Vlad',
- surname: 'Stasenko',
- age: 27,
- fathername: 'Andriyovich',
- sex: 'man'
- },
- personTwo={
- name:'Kate',
- surname:'Yancheva',
- 'age': 27,
- 'fathername': 'Andriivna',
- 'sex': 'woman'
- },
- personThree={
- name:'Sveta',
- surname:'Maksimenko',
- age:
- 48,
- fathername:
- 'Oleksiivna',
- sex:
- 'woman'
- }
- ]
- let json = JSON.stringify(persons)
- personFour = {"name": "Andrey", "surname": "Stasenko", "age": 48, "fathername": "Anatoliiovych", "sex": "man"}
- json= JSON.parse(persons.push(personFour))
- json= JSON.stringify(persons)
- var str = "<table border='1'>"
- for(let key in persons[0]){
- str+= `<td>${key}</td>`
- }
- for (let i=0;i<persons.length;i++){
- str += `<tr style="background: ${i%2?'#f5f5dc':'white'}" >
- <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)
- // HTML th optional ==============================================================================
- let personOne = {
- name: 'Vlad',
- surname: 'Stasenko',
- age: 27,
- fathername: 'Andriyovich',
- sex: 'man',
- car:'BMW',
- married: true
- }
- let personTwo = {
- name:'Kate',
- surname:'Yancheva',
- 'fathername': 'Andriivna',
- 'sex': 'woman'
- }
- let personThree = {
- name:'Sveta',
- surname:'Maksimenko',
- age:
- 48,
- fathername:
- 'Oleksiivna',
- sex:
- 'woman',
- married: false
- }
- let personFour
- let persons = [personOne, personTwo, personThree]
- let json = JSON.stringify(persons)
- personFour = {"name": "Andrey", "surname": "Stasenko", "age": 48, "fathername": "Anatoliiovych", "sex": "man"}
- json= JSON.parse(persons.push(personFour))
- json= JSON.stringify(persons)
- let keys = Object.keys(persons.reduce(function(keysPerson, obj){return Object.assign(keysPerson, obj);},0))
- let str = "<table border='1'>"
- for(let i=0; i<keys.length; ++i){
- str += `<th>${keys[i]}</th>`
- }
- for(let j=0; j<persons.length; ++j){
- str+='<tr>'
- for(k=0; k<keys.length; k++){
- str+=`<td style="background: ${j%2?'#f5f5dc':'white'}"> ${
- (persons[j][keys[k]]) == false? 'Не в браке':
- (persons[j][keys[k]]) == true? 'В браке' :
- (persons[j][keys[k]]) == undefined? 'Поле не заданно': (persons[j][keys[k]])
- } </td>`
- }
- str+='</tr>'
- }
- str += "</table>"
- document.write(str)
- // Задание на синий пояс ==============================================================================
- var someTree = {
- tagName: "table", //html tag
- subTags: [ //вложенные тэги
- {
- tagName: "tr",
- subTags: [
- {
- tagName: "td",
- text: "some text",
- },
- {
- tagName: "td",
- text: "some text 2",
- }
- ]
- }
- ],
- attrs:
- {
- border: 1,
- },
- }
- let strTop = `<${someTree.tagName}`
- let attrs = Object.keys(someTree.attrs)
- let values = Object.values(someTree.attrs)
- for (let i=0; i<attrs.length; i++){
- strTop= strTop + ' ' + attrs[i] + '=' + values[i]
- }
- strTop = strTop + ">"
- for ( j=0; j< someTree.subTags.length; j++){
- let openTR = '<'+ someTree.subTags[j].tagName + '>'
- let closeTR ='</'+ someTree.subTags[j].tagName + '>'
- strTop = strTop + openTR
- for(k=0; k<someTree.subTags[j].subTags.length; k++){
- let openTD = '<'+someTree.subTags[j].subTags[k].tagName+'>'
- let text = someTree.subTags[j].subTags[k].text
- let closeTD = '</'+someTree.subTags[j].subTags[k].tagName+'>'
- strTop=strTop+openTD+text+closeTD
- }
- strTop= strTop+closeTR
- }
- strTop=strTop+`</${someTree.tagName}>`
- console.log(strTop)
- // destruct array ==============================================================================
- let arr = [1,2,3,4,5, "a", "b", "c"]
- let [odd1,even1,odd2,even2,odd3,...words] = arr
- console.log(odd1)
- console.log(even1)
- console.log(odd2)
- console.log(even2)
- console.log(odd3)
- console.log(words)
- // destruct string ==============================================================================
- let arr = [1, "abc"]
- let [number, [s1,s2,s3]] = arr
- console.log(number)
- console.log(s1)
- console.log(s2)
- console.log(s3)
- // destruct 2 ==============================================================================
- let obj = {name: 'Ivan',
- surname: 'Petrov',
- children: [{name: 'Maria'}, {name: 'Nikolay'}]}
- let {children: [{name: name1}, {name: name2}]} = obj
- console.log(name1)
- console.log(name2)
- // destruct 3 ==============================================================================
- let arr = [1,2,3,4, 5,6,7,10]
- let ObjfromArr = {...arr}
- let ObjFromArr2 = {...ObjfromArr, length: arr.length}
- let {0: a, 1: b, length: length} = ObjFromArr2
- console.log(a)
- console.log(b)
- console.log(length)
- // ============================================================================================================================================================
|