如何重新实现JavaScript删除方法?
始终牢记有关delete的以下几点:delete是JavaScript中的关键字,因此不应更改,并且您不能在单个变量中使用delete对象,因为它仅用于删除对象的属性。
delete关键字用于从JavaScript对象中删除属性,如以下代码所示-
示例
<!DOCTYPE html> <html> <body> <p id="demo"></p> <script> var cricketer = { name:"John", rank:3, points: 800 }; delete cricketer.rank; document.getElementById("demo").innerHTML = cricketer.name + " has " + cricketer.rank + " rank."; </script> </body> </html>