如何从 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>
广告