How can I reimplement JavaScript delete method?

JavascriptWeb DevelopmentFront End Technology

Always remember the following points about delete: delete is a keyword in JavaScript, so it shouldn’t be altered, and you cannot use delete objects in single variables since it is used only for deleting properties of objects.

The delete keyword is used to remove a property from a JavaScript object as in the following code −

Example

Live Demo

<!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>
raja
Ali
Published on 18-Jan-2018 07:56:06
Advertisements