123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143 |
- let mas = []
- let a = {
- name: "Misha",
- surname: "Muslim"
- }
- a.fathername = "Svinonich"
- a.age = "24"
- a.country = "Ukraine"
- a.sex = "male"
- a.marriage = true;
- let b = {
- name: "Oleh",
- surname: "Glamazda",
- }
- b.age = "25"
- b.country = "Ukraine"
- b.marriage = false
- let c = {
- name: "Katya",
- surname: "Krasnoshok",
- }
- c.age = "30"
- c.sex = "female"
- let persons = []
- persons.push(a, b, c)
- function fieldsCheck(check) {
- for(let i = 0; i < persons.length; i++) {
- let str = ""
- check = persons[i]
- for(let key in check){
- (key == "name" || key == "surname" ) ? str += ""
- : str += key + " "
- }
- if(str == "") {
- alert("Nothing in " + check.name)
- } else {
- alert(str + " in " + check.name)
- }
- }
- }
- // fieldsCheck()
- persons.push({name: "Tom",
- surname: "Motgan",
- country: "UK",
- marriage: true
- })
- function personsObj(obj) {
- for (let i = 0; i < obj.length; i++){
- console.log(obj[i])
- }
- }
- // personsObj(persons)
- function personsNamSurn(obj) {
- for(let i = 0; i < obj.length; i++) {
- console.log(obj[i].name + " " + obj[i].surname)
- }
- }
- // personsNamSurn(persons)
- function personsValues(obj) {
- let cons = "";
- for(let i = 0; i < obj.length; i++) {
- let check = obj[i]
- for (let key in check) {
- cons += check[key] + " "
- }
- cons += "\n"
- }
- console.log(cons)
- }
- // personsValues(persons)
- function fullName(obj) {
- let value = "";
- for(let i = 0; i < obj.length; i++) {
- let check = obj[i]
- for(let key in check) {
- if(key == "name" || key == "fathername" || key == "surname"){
- value += check[key] + " "
- }
- }
- check.fullName = value
- }
- console.log(value)
- }
- fullName(persons)
- var json = (JSON.stringify(persons, null, " "))
- // console.log(json)
- var e = JSON.parse('{"name":"Petr","surname":"Vlasenco","fathername":"Andreevich","age":"40","country":"Belarus","marriage":"true"}')
- persons.push(e)
- function toHtmlTable(obj) {
- var str = "<table border='1'>"
- for (let i=0;i<obj.length;i++){
- let check = obj[i]
- str += `<tr><td>${i}</td>`
- for (let key in check){
- str += `<td>${check[key]}</td>`
- }
- str += `</tr>`
- }
- str += "</table>"
- document.write(str)
- }
- // toHtmlTable(persons)
- function htmlOptional(obj) {
- debugger
- let str = `<table border='1'><tr><td style = "background-color: yellow"></td>`
- let valueMas =[]
- for (let i=0;i<obj.length;i++){
- let check = obj[i]
- for(let key in check) {
- if(str.includes(key)){
- } else{
- str +=`<th style = "background-color: yellow">${key}</th>`
- valueMas.push(key)
- }
- }
- }
- for (let j=0;j<obj.length;j++){
- let check = obj[j]
- str += `<tr><td style = "background-color: yellow">${j}</td>`
- let keysArr = Object.keys(check);
- for(let k = 0; k < valueMas.length; k++) {
- if(keysArr.indexOf(valueMas[k]) == -1) {
- str += `<td style = "background-color: red"></td>`
- } else {
- str += `<td style = "background-color: #89e0c0">${check[valueMas[k]]}</td>`
- }
- }
- str += `</tr>`
- }
- str += "</table>"
- console.log(str)
- document.write(str)
- }
- // htmlOptional(persons)
|