In my coding project, I am working with an array of objects structured like this:
currentArray = [
{
year: 2011,
asset: {
silver: 322,
gold: 325,
},
},
{
year: 2012,
asset: {
silver: 411,
gold: 2235,
},
},
];
I need to transform this current structure into a new format in JavaScript/TypeScript. Specifically, I want the 'silver' and 'gold' properties from each 'asset' object to be moved up one level next to the 'year'. Additionally, I need to remove the nested 'asset' objects entirely. The desired structure should look like this:
desiredArray = [
{
year: 2011,
silver: 322,
gold: 325,
},
{
year: 2012,
silver: 411,
gold: 2235,
},
];