delete关键字用于删除属性以及属性的值。删除后,该属性将无法使用,然后再重新添加。
在您的示例中,它可以用作-
<html> <body> <p id="demo"></p> <script> var cricketer = { name:"John", rank:3, points: 800 }; delete cricketer.points; document.getElementById("demo").innerHTML = cricketer.name + " scored" + ' '+cricketer.points </script> </body> </html>
输出结果
John scored undefined