Parsing an array of objects to a new form using a dictionary as alias but i wonder if it can be done without the Object.keys
const mapper = {
"card_title": "title",
"card_content": "content",
"card_subtitle": "subtitle"
}
const data = [
{
card_title: "wowo1",
card_content: "wowo1",
card_subtitle: "wowo1",
},
{
card_title: "wowo1",
card_content: "wowo1",
card_subtitle: "wowo1",
},
{
card_title: "wowo1",
card_content: "wowo1",
card_subtitle: "wowo1",
},
]
this is the part where i would like to change it maybe with the spread operator
let results = data.map((r) => {
let obj = {};
Object.keys(mapper).map(key =>
obj[mapper[key]] = r[key]
)
return obj;
})
Expected result that i achieved with the code above
[
{ title: 'wowo1', content: 'wowo1', subtitle: 'wowo1' },
{ title: 'wowo1', content: 'wowo1', subtitle: 'wowo1' },
{ title: 'wowo1', content: 'wowo1', subtitle: 'wowo1' }
]