js删除对象中的某一个字段的方法

方法一:不改变原来对象

   let item = {     name:'张三',     age:'18',     gender:'男'    };    console.log(item) // {age: "18",gender: "男",name: "张三"}    let { age,...params } = item;    console.log(item) // {age: "18",gender: "男",name: "张三"}    console.log(typeof params.age) // undefined    console.log(params) // {gender: "男",name: "张三"}   方法二:直接改变对象    let item1 = {     name:'张三',     age:'18',     gender:'男'    };    console.log(item1) // {age: "18",gender: "男",name: "张三"}    delete item1.name;    console.log(typeof item1.name) // undefined    console.log(item1) // // {age: "18",gender: "男"}
上一篇:1036 Boys vs Girls (25 分)


下一篇:python 缺省参数注意事项