js 删除对象的属性

734 阅读1分钟

方法1

let obj ={
    a:1,
    b:2,
    c:3
}
delete obj.a
delete obj['a']
  • 彻底删除key value
  • 速度较慢

方法2

let obj ={
    a:1,
    b:2,
    c:3
}
obj.a =undefine
  • 速度快
  • key还在

https://flaviocopes.com/how-to-remove-object-property-javascript/