es6删除对象的某个属性

  • Post author:
  • Post category:其他


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)




版权声明:本文为xingmei_ok原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。