<script>
var arr=[
{
name:"lisi",
age:18,
likes:["lol","足球"],
alikes:["asd","fs"],
sex:"male"
},
{
name:"占山",
age:18,
likes:["合法化","足球"],
alikes:["asd","回复"],
sex:"male"
},
{
name:"请问请问",
age:18,
likes:["lol","破解"],
alikes:["asd","fs"],
sex:"male"
}
]
var res = [];
for(var i=0;i<arr.length;i++){
// 解构
var {name,age,likes,alikes} = arr[i];
// 展开
likes.push(...alikes);
// 键值相同 只写一个
var obj = {
name,
age,
likes,
}
res.push(obj)
}
console.log(res)
</script>
版本2
<script>
var arr=[
{
name:"lisi",
age:18,
likes:["lol","足球"],
alikes:["asd","fs"],
sex:"male"
},
{
name:"占山",
age:18,
likes:["合法化","足球"],
alikes:["asd","回复"],
sex:"male"
},
{
name:"请问请问",
age:18,
likes:["lol","破解"],
alikes:["asd","fs"],
sex:"male"
}
]
var res = [];
for(var i=0;i<arr.length;i++){
// 解构
var {name,age,likes,alikes} = arr[i];
// 展开
likes.push(...alikes);
// 键值相同 只写一个
var obj = {
name,
age,
likes,
}
res.push(obj)
}
console.log(res)
</script>