JS object.entries question

Hi js experts, I hope someone can help me to figure out this one, I need to create new array with (“data” and “title”) where data is parent and title is child from .json. It works for first params “data” (assetId, customerIdentifier) but the trick is I can’t figure out how to push child “title” as second params.

.json sample
{
“assetId”: {
“title”: “id”,
“isVisible”: false,
“order”: 0
},
“customerIdentifier”: {
“title”: “name”,
“isVisible”: true,
“order”: 1
}
}

Object.entries(testDT).forEach(([key, value]) => columns.push({ data: key, title: key.title }));

current output: ( data: assetId, title: undefined )
expected output: ( data: assetId, title: id )

Thank you in advance!

const o = {
  assetId: { 
    title: 'assetId title'
  },
  customerIdentifier: {
    title: 'customerIdentifier title'
  }
};
const a = Object.entries(o).map(([k,v]) => ({ data: k, title: v.title }));

console.log(JSON.stringify(a,null,2));
/*
[
  {
    "data": "assetId",
    "title": "assetId title"
  },
  {
    "data": "customerIdentifier",
    "title": "customerIdentifier title"
  }
]
*/
1 Like

Awesome, thank you very much!!!