let persons = [ { name: 'Sergey', surname: 'Honcharenko', age: 28, isMarried: false, }, { name: 'Andrew', surname: 'Klymchuk', middleName: 'Anatoliyovych', haveAJob: true, }, { name: 'Alexander', surname: 'Slobodian', sex: 'male', hasAPet: false, } ]; let personsKeys = []; for (let key in persons) { for (let value in persons[key]) { personsKeys.push(value); } } let personsUniqueKeys = new Set(personsKeys); let str = ""; str += ``; personsUniqueKeys.forEach(item => { str += ``; }); str += ""; for (let key in persons) { str += ``; for (let personsKey in [...personsUniqueKeys]) { if(Object.keys(persons[key]).includes([...personsUniqueKeys][personsKey])) { str += `` } else { str += `` } } str += ""; } str += "
${item}
${persons[key][[...personsUniqueKeys][personsKey]]}-
"; document.write(str);