javascript中基于键的数组转换
我有这样的物体javascript中基于键的数组转换,javascript,arrays,nested,Javascript,Arrays,Nested,我有这样的物体 var object1= { arun={[birthdate=21-02-1995,age=12, height=4.3, weight= 44], [birthdate=21-02-1995,age=21, height=6.2, weight= 65] }, smita={[birthdate=19-08-1995,age=13, height=5.4, weight= 41],
var object1= { arun={[birthdate=21-02-1995,age=12, height=4.3, weight= 44],
[birthdate=21-02-1995,age=21, height=6.2, weight= 65] },
smita={[birthdate=19-08-1995,age=13, height=5.4, weight= 41],
[birthdate=19-08--1995,age=23, height=6.3, weight= 59] },
nikita={[birthdate=16-08-1995, age=12, height=4.3, weight= 46],
[birthdate=16-08-1995, age=26, height=5.3, weight= 48] }
}
还有一个这样的数组,
var array1=[arun,smita]或类似的var array1=[arun]
如果选择了一个名称,我将尝试将此object1转换为类似的名称
var object1=[{birthdate=21-02-1995, name=arun, height=[4.3,6.2]},
{birthdate=21-02-1995, name=arun, age=[12,21]},
{birthdate=21-02-1995, name=arun, weight=[44,65]} ]
如果选择了两个
var object1=[ {birthdate=21-02-1995, name=arun, height=[4.3,6.2]},
{birthdate=21-02-1995, name=arun, age=[12,21]},
{birthdate=21-02-1995, name=arun, weight=[44,65]},
{birthdate=19-08-1995,name=smita, height=[5.4,6.3]},
{birthdate=19-08-1995,name=smita, age=[13,23],
{birthdate=19-08-1995,name=smita, weight=[41,59]} ]
注意:我使用switch case来选择名称
我试着这样按键选择
let value=[];
value.push(array1.map((key) => {
for(let data of object1[key]){
xValue.push(data.height);
yValue.push(data.age)
}
var result={
name: key,
x: xValue,
y: yValue,
}
return result; } ));
像这样的
Object.entries(object1).filter((v) => ['arun', 'smita'].indexOf(v[0])).map((v) => v[1])
所有这些对象都会抛出错误。请添加现有对象。现有对象是否正确?