I've been trying to create a dynamic function which could flatten an nested key/val object inside an array of objects
How do I get this structure? Knowing that i would like to call the keys dynamically and bind the parent key and child key with an _.
Input:
const list = [
{
month: 'Jan',
value: 20,
metric: {
name: 'Rice',
measurement: 'Kg',
is_currency: false
},
entity: {
name: 'Rev',
type: 'limited company'
}
},
{
month: 'Jan',
value: 1000,
metric: {
name: 'Revenue',
measurement: 'Dollars',
is_currency: true
},
entity: {
name: 'Rev',
type: 'limited company'
}
},
]
Expected output:
const list = [
{
month: 'Jan',
value: 20,
metric_name: 'Rice',
metric_measurement: 'Kg',
metric_currency: false,
entity_name: 'Rev',
entity_type: 'limited company'
},
{
month: 'Jan',
value: 1000,
metric_name: 'Revenue',
metric_measurement: 'Dollars',
metric_is_currency: true
entity_name: 'Rev',
entity_type: 'limited company'
},
]