Get your own website Result Size: 625 x 565
x
 
<!DOCTYPE html>
<html>
<body>
<h1>JavaScript Objects</h1>
<h2>The Object.defineProperty() Method</h2>
<p>This example adds a new property to an object.</p>
<p id="demo"></p>
<script>
// Create an object:
const person = {
  firstName: "John",
  lastName: "Doe",
  language: "EN"
};
// Add a property
Object.defineProperty(person, "year", {value:"2008"})
// Display the property
document.getElementById("demo").innerHTML = person.year;
</script>
</body>
</html>