从对象中删除属性

  1. <!DOCTYPE html>
  2. <html>
  3. <body>
  4.  
  5. <h1>JavaScript 对象属性</h1>
  6.  
  7. <p>您可以删除对象属性。</p>
  8.  
  9. <p id="demo"></p>
  10.  
  11. <script>
  12. var person = {
  13. firstname:"Bill",
  14. lastname:"Gates",
  15. age:62,
  16. eyecolor:"blue"
  17. };
  18.  
  19. delete person.age;
  20. document.getElementById("demo").innerHTML =
  21. person.firstname + " is " + person.age + " years old.";
  22. </script>
  23.  
  24. </body>
  25. </html>