-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathobjectPractice2.js
98 lines (95 loc) · 2.88 KB
/
objectPractice2.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
const data = [{
"id": 1,
"name": "Yong",
"phone": "010-0000-0000",
"type": "sk",
"childnode": [{
"id": 11,
"name": "echo",
"phone": "010-0000-1111",
"type": "kt",
"childnode": [{
"id": 115,
"name": "hary",
"phone": "211-1111-0000",
"type": "sk",
"childnode": [{
"id": 1159,
"name": "pobi",
"phone": "010-444-000",
"type": "kt",
"childnode": [{
"id": 11592,
"name": "cherry",
"phone": "111-222-0000",
"type": "lg",
"childnode": []
},
{
"id": 11595,
"name": "solvin",
"phone": "010-000-3333",
"type": "sk",
"childnode": []
}
]
}]
},
{
"id": 116,
"name": "kim",
"phone": "444-111-0200",
"type": "kt",
"childnode": [{
"id": 1168,
"name": "hani",
"phone": "010-222-0000",
"type": "sk",
"childnode": [{
"id": 11689,
"name": "ho",
"phone": "010-000-0000",
"type": "kt",
"childnode": [{
"id": 116890,
"name": "wonsuk",
"phone": "010-000-0000",
"type": "kt",
"childnode": []
},
{
"id": 1168901,
"name": "chulsu",
"phone": "010-0000-0000",
"type": "sk",
"childnode": []
}
]
}]
}]
},
{
"id": 117,
"name": "hong",
"phone": "010-0000-0000",
"type": "lg",
"childnode": []
}
]
}]
}]
const arr = [];
let answer = 0;
function isTypeSk(obj) {
for (let key in obj) {
const value = obj[key];
if (value === 'sk') {
arr.push(obj.name);
} else if (typeof value === 'object') {
isTypeSk(value);
}
}
return arr;
}
answer = isTypeSk(data);
console.log(answer);