js 删除对象里的某个属性

1. 使用delete

let a = {b:1,c:2}
delete a.b//true
console.log(a)//{c:2}

2. 使用解构

let a = {b:1,c:2}
let {b,...a} = a
console.log(a)//{c:2}

3.使用反射

let a = {b:1,c:2}
Reflect.deleteProperty(a,"b");
console.log(a)//{c:2}

 

posted @ 2022-05-05 14:44  bingxiaoxiao  阅读(1170)  评论(0编辑  收藏  举报