如何从JavaScript对象中删除属性?
要从JavaScript对象中删除属性,请使用delete关键字。您可以尝试运行以下代码以了解如何删除属性
示例
<!DOCTYPE html> <html> <body> <p id="demo"></p> <script> var cricketer = { name:"Amit", rank:1, points: 150 }; delete cricketer.rank; document.getElementById("demo").innerHTML = cricketer.name + " has " + cricketer.rank + " rank."; </script> </body> </html>