DEV Community

Deva I
Deva I

Posted on

Objects in Javascript

Definition of Objects:

◾Object in simple words it's a real world entity.

◾An object is a dynamic data structure that stores data as key-value pairs, where each key uniquely identifies its value.

◾Objects are mutable and dynamic properties can be added, modified, or deleted at any time.

◾Object is enclosed with curley braces{}.

◾Objects contains properties and methods.

Syntax:

Const object name(){
properties(key-pairs)
}

CRUD Operation of Object:

C - Create
R - Read
U - Update
D - Delete

Create the Object:

▪️Create a new object or add new keys the existing object.

EXAMPLE PROGRAM:

 .

1.Const is a syntax notation of object.

2.phone is the object

3.The information of inside the curley braces called properties.

4.In the properties left side of the colon(:) is called keys and the next to right side of the colon(:) called values.

5.console.log(phone.price)
Phone - object name
Price - key name
(.) - dot operator.It's used to seperate the object name and key name.

Read in objects:

▪️Read or print the values using keys

EXAMPLE PROGRAM:

1.In the above program was read and print the existing data of objects using the keywords.

2.brand prints their value oneplus.
price prints:25000
color prints:navy blue
Processor prints: Snapdragon 7 gen3
Model prints:Nord CE5.

OUTPUT:

Update in objects:

▪️Update the new value instead of existing value.

EXAMPLE PROGRAM:

1.Update the new value,
phone.price = 28000
phone.color = "Marble mist"
phone.processor = "Mediatek dimensity 8350 Apex " instead of existing values.

2.If you want rearrange the values, using object name and keyword.

3.It takes the value of last rearranged value.

OUTPUT:

Delete in objects:

▪️Delete the property and its value from the objects.

EXAMPLE PROGRAM:

1.Using delete operator to remove the phone color and processor.

2.If the property was successfully removed it returns true

OUTPUT:

Top comments (0)