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 = "
"
for (let i=0;i${i} | `
for (let key in check){
str += `${check[key]} | `
}
str += ``
}
str += "
"
document.write(str)
}
// toHtmlTable(persons)
function htmlOptional(obj) {
debugger
let str = ` | `
let valueMas =[]
for (let i=0;i${key}`
valueMas.push(key)
}
}
}
for (let j=0;j${j} | `
let keysArr = Object.keys(check);
for(let k = 0; k < valueMas.length; k++) {
if(keysArr.indexOf(valueMas[k]) == -1) {
str += ` | `
} else {
str += `${check[valueMas[k]]} | `
}
}
str += `
`
}
str += "
"
console.log(str)
document.write(str)
}
// htmlOptional(persons)