繁体   English   中英

如何将嵌套数组转换为简单的 typescript object

[英]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.是我想念的东西。

[
   {
      "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"
      ]
   }
]

我需要像这样转换以将数据显示为图表。

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] })));

不知道为什么每个value都是335 ,但这里是 -

 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);

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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