delete a property or method from an object using the delete keyword. - Javascript Language Basics

Javascript examples for Language Basics:Introduction

Description

delete a property or method from an object using the delete keyword.

Demo Code

ResultView the demo in separate window

<!DOCTYPE HTML>
<html>
          <head>
              <title>Example</title>
          </head>
          <body>
              <script type="text/javascript">
                  var myData = {//from w w w . j av  a  2s .c  o m
                      name: "java2s.com",
                      topic: "CSS",
                  };

                  myData.sayHello = function() {
                    document.writeln("Hello");
                  };


                  delete myData.name;
                  delete myData["topic"];
                  delete myData.sayHello;
              </script>
    </body>
</html>

Related Tutorials