1.利用展开运算符和解构完成以下
[{
name:”张三”,
age:165,
likes:[“发顺丰”,”jf”,”音乐9”,”10电影”],
}]
<body>
<script>
var arr = [
{
name:"lisi",
age:18,
likes:["lol","足球"],
alikes:["音乐","电影"],
sex:"male"
},
{
name:"王五",
age:17,
likes:["al","栏球"],
alikes:["防抖","放到"],
sex:"male"
},
{
name:"张三",
age:165,
likes:["发顺丰","jf"],
alikes:["音乐9","10电影"],
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>
</body>