TypeScript
by Nic Fontaine
CSS
body {
background: #20262E;
padding: 20px;
font-family: Helvetica;
}
#app {
background: #fff;
border-radius: 4px;
padding: 20px;
transition: all 0.2s;
text-align: center;
}
TypeScript
const flattenObject = (obj: object, parentKey?: string): [string, any][] => {
return Object.entries(obj).flatMap(([key, value]) => {
const newKey = parentKey ? `${parentKey}.${key}` : key;
if (typeof value === 'object' && !Array.isArray(value) && value !== null) {
return flattenObject(value, newKey);
}
return [[newKey, value]];
});
};
const testObject = {
a: {
b: [3, 4, 5]
}
}
console.log(flattenObject(testObject));