JavaScript ES5 Object Methods

1/22/2020 2:42:48 AM

JavaScript ES5 introduce some method for using our object to find, search, sort, replace the under-object property value. This object method is very help full for programmer. When we create an object then we can change the value of the specific property from the object then we use the method and very easily we can do it. Now given bellow some object method name:

// Adding or changing an object property
Object.defineProperty(object, property, descriptor)

// Adding or changing many object properties
Object.defineProperties(object, descriptors)

// Accessing Properties
Object.getOwnPropertyDescriptor(object, property)

// Returns all properties as an array

// Returns enumerable properties as an array

// Accessing the prototype

// Prevents adding properties to an object
// Returns true if properties can be added to an object

// Prevents changes of object properties (not values)
// Returns true if object is sealed

// Prevents any changes to an object
// Returns true if object is frozen

Now given bellow the object method example code and explain the code:

<!DOCTYPE html>
<script type="text/javascript">
 //JavaScript object method 
var human = {
  firstName: "Reza",
  lastName : "Karim",
  language : "EN" 
// Change a property
Object.defineProperty(human, "language", {value:"Bang"})
//print the changed value

In this code we show the one object method example code how to work. First create an object name as ‘human’ then this object contain three property like ‘firstName’, ‘lastName’, ‘language’ then assign the default value of the object. Now we use the object method change the language value also print the language value using ‘console.log’.