@financial-times/n-conversion-forms
Version:
Containing jsx components and styles for forms included on Accounts and Acqusition apps (next-signup, next-profile, next-retention, etc).
15 lines (13 loc) • 400 B
JavaScript
//Recursively flattens a nested object.
//For example: input: {a:{b:1}} -> output: {b:1}
const flattenObj = (obj, out = {}) => {
Object.keys(obj).forEach((key) => {
if (typeof obj[key] === 'object') {
out = flattenObj(obj[key], out); //recursively call for nested objects
} else {
out[key] = obj[key]; //direct assign for values
}
});
return out;
};
module.exports = { flattenObj };