DEV Community

Cover image for OBJECT
Vinoth Kumar
Vinoth Kumar

Posted on

OBJECT

OBJECT IN JS: A dynamic data structure that stores related data as key-value pairs, where each key uniquely identifies its value.

  • The values of properties can be primitives, objects, or functions.
  • Objects are mutable and dynamic properties can be added, modified, or deleted at any time.
  • Objects allow data grouping and encapsulation, making it easier to manage related information and behaviour together.

PRIMARY WAYS TO CREATE AN OBJECT:

  1. Creation Using Object Literal.
  2. Creation Using new Object() Constructor.

CREATION USING OBJECT LITERAL: object literal syntax allows you to define and initialize an object with curly braces {}, setting properties as key-value pairs.

EXAMPLE:

const mobile1 = {
    name: "iphone",
    price: 50000,
    storage: "512TB"
};
console.log(mobile1.price);
Enter fullscreen mode Exit fullscreen mode

CREATION USING OBJECT() CONSTRUCTOR: A static method creates a new object, using an existing object as the prototype of the newly created object.

EXAMPLE:

function Mobile(){}
let mobile = new Mobile();
mobile.name = "Sourav";
mobile.age = 23;
mobile.job = "Developer";

console.log(mobile);
Enter fullscreen mode Exit fullscreen mode

OPERATIONS ON OBJECT:

  • Accessing Object Properties.
  • Modifying Object Properties.
  • Adding Properties to an Object.
  • Removing Properties from an Object.
  • Checking if a Property Exists.
  • Iterating Through Object Properties.
  • Merging Objects.
  • Object Length.

Top comments (0)