JavaScript 删除对象属性

1. 解构赋值

const obj = {
    a: 1,
    b: 2,
    c: 3
}

const { a, ...s } = obj

console.log(s) // { b: 2, c: 3 }

2. delete 关键字

const obj = {
    a: 1,
    b: 2,
    c: 3
}

delete obj.a
delete obj.b

console.log(obj) // { c: 3 }

你可能感兴趣的:(json,react.js,node.js)