我有此信息。我正在寻求将该数组转换为打字稿对象。我使用Object.Keys和Object.Values从嵌套Object生成了该对象。我尝试了很多选项,但看起来仅是Object.keys和Object.Values返回数组。这是我所缺少的。
[
{
"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' }
];
答案 0 :(得分:0)
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] })));
答案 1 :(得分:0)
不确定为什么每个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);