How to remove a property from a JavaScript Object
×

How to remove a property from a JavaScript Object?

3023

In JavaScript, we can use the 'delete' operator to completely remove the properties from the JavaScript object. Deleting is the way to remove a property from an object.

When you remove a property from an object property set to undefined or null. Delete operator not work when you used on predefined JavaScript object properties. It may be harmful for your application.

Program:

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title> Remove a Property from a JavaScript Object </title>
</head>
<body>
  <h1>Remove a Property from a JavaScript Object </h1>
    <p id="demonew"></p>
    <script>
  var person = {
  firstname: "John",
  lastname: "Doe",
  age: 29,
  eyecolor: "black"
};

delete person.age;
document.getElementById("demonew").innerHTML =
person.firstname + " is " + person.age + " years old.";
</script>
</body>
</html>



Best WordPress Hosting


Share:


Discount Coupons

Get a .COM for just $6.98

Secure Domain for a Mini Price



Leave a Reply


Comments
    Waiting for your comments