You can do this by recursively traversing the object:
function getDeepKeys(obj) {
var keys = [];
for(var key in obj) {
keys.push(key);
if(typeof obj[key] === "object") {
var subkeys = getDeepKeys(obj[key]);
keys = keys.concat(subkeys.map(function(subkey) {
return key + "." + subkey;
}));
}
}
return keys;
}
Running getDeepKeys(abc)
on the object in your question will return the following array:
["1", "2", "3", "4", "5", "5.test", "5.tester", "5.tester.name", "count", "counter", "counter.count"]
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…