当前位置:网站首页>ES6 deleting an attribute of an object

ES6 deleting an attribute of an object

2022-06-13 07:53:00 Xizhou-

1. Do not change the original object

Method 1( Delete age Attribute as an example )

const obj = {
	name: 'xingxing',
	gender: 'girl',
	age: 24
};
const objNew = (({
	name,
	gender
}) => ({
	name,
	gender
}))(obj)
console.log(obj)
console.log(objNew)

Output is as follows :

Method 2( Delete age For example )

const obj = {
	name: 'xingxing',
	gender: 'girl',
	age: 24
};

let {age,...objNew} = obj
console.log(objNew)
console.log(obj)

2 delete Delete , Change the original array

Delete age Attribute as an example

let obj = {
	name: 'xingxing',
	gender: 'girl',
	age: 24
};
delete obj.age
console.log(obj)

原网站

版权声明
本文为[Xizhou-]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/164/202206130752040463.html