Object Methods
Object Methods
Object methods
List of content:
Object methods
Types and examples
Object Methods:
Actions on objects are carried out using methods. An object Property that includes a function declaration is
known as an object method.
name: 'Alex',
age: 27,
salary:10000
};
console.log(keys);
Output:
Object.values():
name: 'Alex',
age: 27,
salary:10000
};
console.log(rec);
Output:
Object.entries()
This method is used to return an array of enumerable property [key, value] pairs of the object passed
as the parameter.
var emp = {
name: 'Alex',
age: 27,
salary:10000
};
console.log(Object.entries(emp)[1]);
Output:
Object.assign():
The values and properties of one or more source objects are copied to a destination object using the
Object.assign() function.
name: 'Alex',
age: 27,
salary:10000
};
console.log(emp_obj);
Output:
Object.freeze():
Changing a frozen object is impossible. It prevents the addition and deletion of properties. Additionally, it
prevents changes to property values from occurring unless an object is involved.
var emp = {
name: 'Alex',
age: 27,
salary:10000
};
Object.freeze(emp);
console.log(Object.isFrozen(emp));
Output:
Object.seal():
It is a method identical to Object.freeze(). You cannot add or remove an object's properties, but you can
edit the value of an existing property.
name: 'Alex',
age: 27,
salary:10000
};
Object.seal(emp);
console.log(Object.isSealed(emp));
Output: