Browse Source

Bonus task HW#5

master
Anna Smaglo 1 year ago
parent
commit
7174748fdc
1 changed files with 320 additions and 0 deletions
  1. +320
    -0
      Bonus task HW#5.html

+ 320
- 0
Bonus task HW#5.html View File

@ -0,0 +1,320 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Bonus task for HW #5</title>
</head>
<body>
<script>
// Задание: Создать универсальную функцию для вывода всех свойств объектов и всех элементов массивов, включая вложенные объекты всех уровней
var randomData = [
{
"_id": "5caf2781f07a9aafb196251e",
"index": 0,
"guid": "d5ad3014-b499-4738-a6c4-221fb43d97d4",
"isActive": true,
"balance": "$3,342.96",
"picture": "http://placehold.it/32x32",
"age": 39,
"eyeColor": "blue",
"name": "Marisa Bowman",
"gender": "female",
"company": "OPTICALL",
"email": "marisabowman@opticall.com",
"phone": "+1 (879) 529-2286",
"address": "415 Gates Avenue, Westboro, Georgia, 6602",
"about": "Duis exercitation cupidatat esse consequat incididunt officia sit. Et tempor pariatur amet minim exercitation laboris laborum. Do eiusmod duis minim ut aute sunt. Incididunt elit sunt sit ullamco amet ullamco excepteur nisi. Ad nisi nulla incididunt magna incididunt occaecat aliquip officia id commodo veniam. Consequat voluptate Lorem quis duis. Adipisicing nostrud nulla quis laboris eu cillum tempor deserunt voluptate ad aliquip.\r\n",
"registered": "2018-03-21T11:01:59 -02:00",
"latitude": -74.682317,
"longitude": 95.598612,
"tags": [
"velit",
"sit",
"amet",
"nulla",
"pariatur",
"et",
"fugiat"
],
"friends": [
{
"id": 0,
"name": "Pamela Hardin"
},
{
"id": 1,
"name": "Spence Price"
},
{
"id": 2,
"name": "Alma Rivas"
}
],
"greeting": "Hello, Marisa Bowman! You have 5 unread messages.",
"favoriteFruit": "banana"
},
{
"_id": "5caf2781c89dafa4e08c2cd5",
"index": 1,
"guid": "1f65a223-6d44-4127-bbb4-69626f0d7fac",
"isActive": true,
"balance": "$1,886.63",
"picture": "http://placehold.it/32x32",
"age": 31,
"eyeColor": "green",
"name": "Iris Stephens",
"gender": "female",
"company": "MUSAPHICS",
"email": "irisstephens@musaphics.com",
"phone": "+1 (984) 411-2633",
"address": "450 Temple Court, Wikieup, Illinois, 754",
"about": "Cillum velit officia esse nostrud sint aliquip. Esse elit fugiat anim commodo. Sunt est exercitation in est do ut anim voluptate ex commodo proident excepteur officia.\r\n",
"registered": "2017-01-05T03:43:41 -02:00",
"latitude": 21.362095,
"longitude": 0.145978,
"tags": [
"dolor",
"velit",
"commodo",
"tempor",
"dolor",
"sit",
"quis"
],
"friends": [
{
"id": 0,
"name": "Daphne Clarke"
},
{
"id": 1,
"name": "Amelia Hammond"
},
{
"id": 2,
"name": "Cathleen Dorsey"
}
],
"greeting": "Hello, Iris Stephens! You have 1 unread messages.",
"favoriteFruit": "banana"
},
{
"_id": "5caf2781c87f9e0fd94032af",
"index": 2,
"guid": "40d03650-4dae-441e-9e99-0c2559a495f0",
"isActive": false,
"balance": "$1,318.35",
"picture": "http://placehold.it/32x32",
"age": 35,
"eyeColor": "blue",
"name": "Johanna Mccoy",
"gender": "female",
"company": "ZOMBOID",
"email": "johannamccoy@zomboid.com",
"phone": "+1 (826) 568-2003",
"address": "772 Otsego Street, Camas, Virginia, 8567",
"about": "Sunt irure fugiat voluptate pariatur. Est veniam exercitation et sit reprehenderit fugiat magna cillum excepteur dolor consectetur. Laborum nisi ullamco laborum laborum dolore esse reprehenderit ipsum qui aliquip non officia ullamco. Nostrud ipsum irure irure veniam incididunt nisi excepteur deserunt est ipsum ad dolore. Consectetur consequat incididunt excepteur culpa sint voluptate pariatur ut. Eiusmod deserunt officia officia anim amet ad officia. Fugiat id aute non et ut aliqua fugiat.\r\n",
"registered": "2015-04-15T02:13:05 -03:00",
"latitude": 52.251825,
"longitude": -155.685381,
"tags": [
"ut",
"dolor",
"non",
"aliqua",
"magna",
"voluptate",
"id"
],
"friends": [
{
"id": 0,
"name": "Aileen Dickerson"
},
{
"id": 1,
"name": "Teri Hester"
},
{
"id": 2,
"name": "Shirley Silva"
}
],
"greeting": "Hello, Johanna Mccoy! You have 10 unread messages.",
"favoriteFruit": "strawberry"
},
{
"_id": "5caf2781f53f11e3073eb49a",
"index": 3,
"guid": "dbfffd4a-92a8-467d-bf33-b69b05beab6c",
"isActive": false,
"balance": "$3,849.82",
"picture": "http://placehold.it/32x32",
"age": 23,
"eyeColor": "blue",
"name": "Stark Rodgers",
"gender": "male",
"company": "QUAILCOM",
"email": "starkrodgers@quailcom.com",
"phone": "+1 (965) 467-2103",
"address": "995 Madison Place, Starks, California, 4960",
"about": "Do culpa elit aliqua velit cupidatat esse laborum exercitation nulla non. Tempor mollit tempor laboris nisi pariatur. Nostrud enim laboris culpa ipsum veniam pariatur exercitation. Nulla voluptate anim culpa et. Pariatur mollit consectetur aliqua sit esse non ipsum magna mollit ullamco eu nulla ipsum labore.\r\n",
"registered": "2015-07-20T12:47:24 -03:00",
"latitude": 85.624827,
"longitude": 177.576369,
"tags": [
"proident",
"occaecat",
"aliqua",
"magna",
"aliquip",
"cillum",
"minim"
],
"friends": [
{
"id": 0,
"name": "Yates Hunt"
},
{
"id": 1,
"name": "French Mcintyre"
},
{
"id": 2,
"name": "Maddox Huber"
}
],
"greeting": "Hello, Stark Rodgers! You have 9 unread messages.",
"favoriteFruit": "banana"
},
{
"_id": "5caf2781c33836c0813f60ab",
"index": 4,
"guid": "6f77c5fd-5e30-432b-8106-67c666ab5141",
"isActive": true,
"balance": "$1,174.94",
"picture": "http://placehold.it/32x32",
"age": 31,
"eyeColor": "brown",
"name": "Gallegos Lawrence",
"gender": "male",
"company": "CENTREE",
"email": "gallegoslawrence@centree.com",
"phone": "+1 (802) 526-2462",
"address": "803 Tapscott Avenue, Edmund, South Carolina, 7074",
"about": "In aute aliquip dolore in deserunt. Et ad Lorem proident et. Amet incididunt ullamco dolore Lorem fugiat enim labore ut pariatur incididunt. Esse ullamco ad aliquip nisi deserunt minim irure reprehenderit excepteur aliquip.\r\n",
"registered": "2016-03-22T12:36:25 -02:00",
"latitude": 2.403943,
"longitude": 130.700535,
"tags": [
"occaecat",
"ut",
"ipsum",
"aliquip",
"cillum",
"culpa",
"mollit"
],
"friends": [
{
"id": 0,
"name": "Pena Leach"
},
{
"id": 1,
"name": "Finch Grant"
},
{
"id": 2,
"name": "Meghan Swanson"
}
],
"greeting": "Hello, Gallegos Lawrence! You have 8 unread messages.",
"favoriteFruit": "strawberry"
},
{
"_id": "5caf27814020d9aaf3195ad8",
"index": 5,
"guid": "6de81972-4480-48d0-9b04-5f668deb9b27",
"isActive": true,
"balance": "$1,627.38",
"picture": "http://placehold.it/32x32",
"age": 20,
"eyeColor": "blue",
"name": "Patton Bowers",
"gender": "male",
"company": "DANCITY",
"email": "pattonbowers@dancity.com",
"phone": "+1 (855) 416-3102",
"address": "523 Cherry Street, Dupuyer, Ohio, 1101",
"about": "Ullamco adipisicing quis sit laborum reprehenderit ea officia velit. Eu est sint Lorem culpa elit. Occaecat tempor non deserunt laboris nostrud aliqua veniam irure amet enim Lorem aute tempor. Eiusmod labore proident magna fugiat incididunt non ex fugiat irure dolore aliquip aute.\r\n",
"registered": "2015-09-05T07:03:04 -03:00",
"latitude": 60.838908,
"longitude": -133.753797,
"tags": [
"occaecat",
"aute",
"duis",
"veniam",
"dolore",
"do",
"Lorem"
],
"friends": [
{
"id": 0,
"name": "Greta Barrera"
},
{
"id": 1,
"name": "Keith Irwin"
},
{
"id": 2,
"name": "Holland Dalton"
}
],
"greeting": "Hello, Patton Bowers! You have 1 unread messages.",
"favoriteFruit": "banana"
}
]
function inspectData(inpData) {
console.log(inpData);
var result = ``;
var keyName;
var deepLevel = 0;
function traceObj(data) {
if (typeof data === "object") {
if (Array.isArray(data)) {
data.forEach(function (item) {
traceObj(item);
})
} else {
for (key in data) {
keyName = key;
traceObj(data[key]);
}
}
} else {
result += `${keyName}: ${data}<br>`;
}
}
traceObj(inpData);
return result;
}
var resultArray = inspectData(randomData);
document.write(resultArray);
</script>
</body>
</html>

Loading…
Cancel
Save