<script>
// 针对json对象
/* tips:只能获取对象中的第一层属性 */
var obj ={
name:"lisi",
age:19,
likes:{
a:10
}
}
var {name,age,likes} = obj;
console.log(likes)
</script>
例子
<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"
}
]
/*
[{
name:"张三",
age:165,
likes:["发顺丰","jf","音乐9","10电影"],
}]
*/
var res = [];
for(var i=0;i<arr.length;i++){
var {name,age,likes,alikes} = arr[i];
likes.push(...alikes);
res.push({
name,
age,
likes
})
}
console.log(res);
</script>