项目中经常会对数据进行处理,删除对象中的某个或多个属性,代码如下:
let obj = {
id:"123456",
name:"西瓜",
type:"水果",
season:"夏天",
property:"很甜",
}
// newObj默认接收剩余的属性
let {property,...newObj} = obj //删除属性property
console.log(newObj) //{id:"123456",name:"西瓜",type:"水果",season:"夏天"}
console.log(obj) //{id: "123456", name: "西瓜", type: "水果",season:"夏天",property:"很甜"}
let {property,season,...newObj1} = obj //删除属性property,season
console.log(newObj1) //{id:"123456",name:"西瓜",type:"水果"}
console.log(obj) //{id: "123456", name: "西瓜", type: "水果",season:"夏天",property:"很甜"}