In JavaScript, Object methods are used to interact with objects, allowing you to perform various actions like adding properties, accessing properties, and manipulating the object in different ways.
🔹 Key JavaScript Object Methods:
Object.keys() – Returns an array of a given object's property names
Object.values() – Returns an array of a given object's property values
Object.entries() – Returns an array of a given object's own enumerable string-keyed property [key, value] pairs
Object.assign() – Copies values of all enumerable properties from one or more source objects to a target object
Object.freeze() – Freezes an object, preventing new properties from being added and existing properties from being modified or deleted
📌 Object.keys()
The Object.keys() method returns an array of the object's own enumerable property names (keys).
Example: Get Keys of an Object
📌 Object.values()
The Object.values() method returns an array of the given object's property values.
Example: Get Values of an Object
📌 Object.entries()
The Object.entries() method returns an array of a given object's own enumerable string-keyed property [key, value] pairs.
Example: Get Key-Value Pairs of an Object
📌 Object.assign()
The Object.assign() method copies all enumerable properties from one or more source objects to a target object.
Example: Assigning Properties from One Object to Another
📌 Object.freeze()
The Object.freeze() method freezes an object. Once frozen, new properties cannot be added, and existing properties cannot be modified or deleted.
Example: Freeze an Object
📌 Try It Yourself
Try the object methods on the object below:
Operation result will appear here
📘 Summary:
JavaScript Object methods allow you to interact with objects by retrieving their keys, values, entries, assigning properties, or freezing the object. These methods are essential for managing and modifying JavaScript objects in your code.
🌟 Enjoyed Learning with Us?
Help others discover Technorank Learning by sharing your honest experience. Your support inspires us to keep building!