var obj = { a: { b: { c: { f: "aa" } }, d: { e: { g: "bb" }, h: { i: "cc" } }, j: { k: "dd" } } }
// [f,g,i,c,e,h,k,b,d,j,a]
function ff(obj) {
let arr = [obj]
let ans = []
let temp = []
let output = []
while(arr.length) {
let item = arr.shift()
for(let k in item) {
output.push(k)
if(typeof item[k] === 'object') {
temp.push(item[k])
}
}
if(arr.length === 0) {
arr = temp
temp = []
ans = output.concat(ans)
output = []
}
}
return ans
}
console.log(ff(obj))