Methods to delete an attribute from an object and create a new object are:

Var obj = {aa: 1, bb: 2, dd: 4, ee: 5} var obj = {aa: 1, bb: 2, cc: 3, dd: 4, ee: 5}Copy the code

1.for + if

let newObj = {}
for (let key in obj) {
  if (key !== 'cc') {
    newObj[key] = obj[key];
  }
} 
Copy the code

2 delete

let newObj = JSON.parse(JSON.stringify(obj, ['aa', 'bb', 'cc', 'dd', 'ee']));
delete newObj.cc;
Copy the code

3. The second argument to json.stringify

let newObj = JSON.parse(JSON.stringify(obj, ['aa', 'bb', 'dd', 'ee']));
Copy the code

4. Deconstruct assignments

let {aa, bb, dd, ee} = obj;
let newObj = {aa, bb, dd, ee};
Copy the code

5. The rest parameters

const delKey = (prop, { [prop]: _, ... rest }) => rest; let newObj = delKey('cc', obj);Copy the code

Where _ can be any character, for example, 3 for cc

6.undifined

obj.cc = undefined;
let newObj = JSON.parse(JSON.stringify(obj));
Copy the code