Currently, I'm working with an object and iterating through it to retrieve outputs as shown below:
var obj = {
"first": {
"Bob": {
"1": "foo",
"2": "bar"
},
"Jim": {
"1": "baz"
}
},
"second": {
"Bob": {
"1": "qux"
},
"Jim": {
"1": "quux"
},
},
}
for (let position in obj) {
console.log(`In ${position} position`);
let pos = obj[position];
for (let name in pos) {
person = pos[name];
for (let item in person) {
let thing = person[item];
console.log(`${position} ${name} ${item} ${thing}`)
}
}
}
While this method works, it seems a bit convoluted due to the nested for
loops. Is there a more elegant solution using ES6/ES7+ features?