I am creating an object
with values from an api response
. Is there a neater way to do this?
My code:
const variables = {
name: result.data.data.table.name,
org: the_org,
val1: result.data.data.table.val1,
val2: result.data.data.table.val2,
val3: result.data.data.table.val3,
val4: result.data.data.table.val4,
val5: result.data.data.table.val5,
val6: result.data.data.table.val6,
val7: new_vals7,
};
Some values come from an api call
and some are not. Was just wondering is there is a neater way to do this?
const obj = ["name","val1",..."val6"].reduce((acc,curr)...,{{org:the_org,val7:new_val7}})
result.data.data.table
or are there more?const variables = ['name', 'val1','val2', 'val3', 'val4', 'val5', 'val6'].reduce((acc,curr) => ({...acc,[curr]:result.data.data.table[curr]}),{org:the_org,val7:new_vals7})
result.data.data.table
into the new object.