-
Notifications
You must be signed in to change notification settings - Fork 21
/
sample.js
39 lines (30 loc) · 823 Bytes
/
sample.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
// sample.js
var myList = {
objectOne: { item1: { objname: "details9"} },
objectTwo: { itemYes: { anothername: "details123"}, itemTwo: { test: "details444"}, itemHello: { hello: "details666"} }
};
var printList = [];
function getObjValues(obj){
var result = [];
Object.keys(obj).forEach(function (key) {
if(Object.keys(obj[key]) !== 0){
result.push(getObjValues(obj[key]));
}
});
return result;
}
function listAllValues(o){
var objectToInspect = o;
var result = [];
for(var key in objectToInspect) {
var nestedObj = myList["objectTwo"][key];
for(key in nestedObj){
var objValue = nestedObj[key];
}
result.push(objValue);
};
return result;
}
printList = listAllValues(myList["objectTwo"]);
console.log(getObjValues(myList["objectTwo"]));
// console.log(printList);