const data = [
{
id: 0,
type: 'Left',
count: 3,
accessories: {
aa: 'V S B',
bf: 'H',
dc: 'P E',
},
},
{
id: 1,
type: 'Right',
count: 2,
accessories: {
qw: 'L',
bm: 'K L',
},
},
];
const newData = data.map((item) => ({
name: `Name #${item.id}`,
attributes: Object.values(item.accessories).map((accessory) => ({
trait_type: 'accessory',
value: accessory,
})).concat([{
trait_type: 'type',
value: item.type,
}]),
}));
console.log(newData);