The ES5 Object method in javascript is used to find more methods to interact with the objects.
The ES5 Object method can do:
- prevents enumeration
- manipulation
- deletion
- prevent addition of new features
- getters and setters
Syntax:
Object.defineProperty(object, property, {value : value})
The following Meta Data value can be true or false:
- writable
- enumerable
- configurable
Example to get all properties:
<!DOCTYPE html>
< html >
< body >
< div style = "background-color: green;" >
< center >
< h2 >Geeksforgeeks</ h2 >
< h3 >The properties of the object are:</ h3 >
< h3 id = "demo" ></ h3 >
</ center >
</ div >
< script >
var person = {
name: "xyz",
address: "noida",
language: "hindi"
}
// Change Property
Object.defineProperty(person,
"language", { enumerable: false });
document.getElementById("demo").innerHTML
= Object.getOwnPropertyNames(person);
</ script >
</ body >
</ html >
|

Example to get enumerable properties:
<!DOCTYPE html>
< html >
< body >
< div style = "background-color: green;" >
< center >
< h2 >Geeksforgeeks</ h2 >
< h3 >The properties of the object are:</ h3 >
< h3 id = "demo" ></ h3 >
</ center >
</ div >
< script type = "text/javascript" >
var person = {
name: "xyz",
address: "noida",
language: "hindi"
}
// Change Property
Object.defineProperty(person,
"language", { enumerable: false });
document.getElementById("demo")
.innerHTML = Object.keys(person);
</ script >
</ body >
</ html >
|

Example to add a property:
<!DOCTYPE html>
< html >
< body >
< div style = "background-color: green;" >
< center >
< h2 >Geeksforgeeks</ h2 >
< h3 >
The mobno property is added and
the value of that property is:
</ h3 >
< h3 id = "demo" ></ h3 >
</ center >
</ div >
< script >
var person = {
name: "xyz",
address: "noida",
language: "hindi"
}
Object.defineProperty(person,
"mobno", { value: "979889xxxx" });
// Display Properties
document.getElementById("demo")
.innerHTML = person.mobno;
</ script >
</ body >
</ html >
|

Whether you're preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape,
GeeksforGeeks Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we've already empowered, and we're here to do the same for you. Don't miss out -
check it out now!
Last Updated :
07 Jan, 2021
Like Article
Save Article