let entry: object = {
a: {
b: {
c: {
dd: 'abcdd',
},
},
d: {
xx: 'adxx',
},
e: 'ae',
},
};
let output: object = {
'a.b.c.dd': 'abcdd',
'a.d.xx': 'adxx',
'a.e': 'ae',
};
private resolveFlatObject(obj: object, parentKey: string = '', result: object = {}): object {
for (const key in obj) {
if (Object.prototype.hasOwnProperty.call(obj, key)) {
let keyName: string = `${parentKey}${key}`;
if (typeof obj[key] === 'object') {
this.resolveObjctToString(obj[key], `${keyName}.`, result);
} else {
result[keyName] = obj[key];
}
}
}
return result;
}
文章標籤
全站熱搜