1.不改变原始对象
方法1(删除age属性为例)
const obj = { name: 'xingxing', gender: 'girl', age: 24 }; const objNew = (({ name, gender }) => ({ name, gender }))(obj) console.log(obj) console.log(objNew)
输出如下:
方法2(删除age为例)
const obj = { name: 'xingxing', gender: 'girl', age: 24 }; let {age,...objNew} = obj console.log(objNew) console.log(obj)
2 delete删除,改变原有数组
删除age属性为例
let obj = { name: 'xingxing', gender: 'girl', age: 24 }; delete obj.age console.log(obj)