Objects store key-value pairs of data and can define behaviour via functions.
Values are accessed through keys.
Output:
Let's add key-value pair to object and then modify it:
Output:
An object may contain function in which this
points to the object itself.
Let's look at the following example:
In order to access object's property (name
and city
)
the keyword this
is used.
In order to loop through object's keys and values Object.entries
can be used.
Output:
Notice: Object.entries
cannot be used in Internet Explorer.