简体   繁体   中英

How to convert nested Array into simple typescript object

I have this information.I am looking to convert this array into typescript object.This object I generated from nested Object using Object.Keys and Object.Values.I try many options but it's look Object.keys and Object.Values only returns Arrays.Is something I am missing.

[
   {
      "value":[
         2.54,
         14.92,
         3.5,
         2.57,
         1.64,
         8.85,
         5.59,
         51.63,
         3.02,
         5.74
      ],
      "name":[
         "input",
         "output",
         "initialization",
         "pvtProperties",
         "rockProperties",
         "equationSetup",
         "networkWells",
         "solver",
         "update",
         "misc"
      ]
   }
]

I need to convert like this to show data into Chart.

data:[
        { value: 335, name: 'input' },
        { value: 335, name: 'output' },
        { value: 335, name: 'initialization' },
        { value: 335, name: 'pvtProperties' },
        { value: 335, name: 'rockProperties' },
        { value: 335, name: 'equationSetup' },
        { value: 335, name: 'networkWells' },
        { value: 335, name: 'solver' },
        { value: 335, name: 'update' },
        { value: 335, name: 'misc' }
      ];

 let arr = [ { value: [ 2.54, 14.92, 3.5, 2.57, 1.64, 8.85, 5.59, 51.63, 3.02, 5.74 ], name: [ "input", "output", "initialization", "pvtProperties", "rockProperties", "equationSetup", "networkWells", "solver", "update", "misc" ] } ]; console.log(arr[0].value.map((v, i) => ({ value: v, name: arr[0].name[i] })));

Not sure why each value is 335 , but here it is -

 const arr = [ { "value":[ 2.54, 14.92, 3.5, 2.57, 1.64, 8.85, 5.59, 51.63, 3.02, 5.74 ], "name":[ "input", "output", "initialization", "pvtProperties", "rockProperties", "equationSetup", "networkWells", "solver", "update", "misc" ] } ]; const data = arr[0].name.map(e => ({value: 335, name: e})); console.log(data);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM