Object methods: How to work with object in javascript

What are Objects? What is Object methods? Types of Object methods Object.keys() Object.values() Object.entries() Object.assign() Object.freeze()

What are Objects?

It is one of the datatypes of Javascript. A object is used to store various keyed collections and more complex entities.

An object is an entity(properties and method) with a certain state and behavior.

An object is used to show many properties in a single variable named 'object'.

Here is a example of an object named 'car'. A car has different properties like price, manufacturing year, model etc. You can see it in an object.

const car={model:"Honda City",

fuel_capacity: 40" I",

company: "Honda"}

In this example, Object 'car' has three keys(model, fuel_capacity, company) and its values(Honda City, 40 I, Honda).

What is Object methods?

We do make actions on objects using methods. An object property that includes a function declaration is known as an object method.

Types of Object methods

Here are some object methods.

  1. Object.keys()

  2. Object.values()

  3. Object.entries()

  4. Object.assign()

  5. Object.freeze()

  6. Object.seal()

Object.keys()

It is used to returns an array of an object's property names.

Output:

Object.values()

It returns an array of values of an object's property.

Output:

Object.entries()

This method is used to return an array of enumerable property[key,value] pairs of the object passed as the parameter.

Output:

Object.assign()

It is used to copy one object's key-value to another object.

Output:

Object.freeze()

It is used to prevent addition and deletion of properties.

Output:

Object.seal()

It is like Object.freeze() method, but it gives permission to edit the value of existing property.

Output:

Did you find this article valuable?

Support WebIndia by becoming a sponsor. Any amount is appreciated!