Objects

Objects store key-value pairs of data and can define behaviour via functions.

Creation

Empty Object

Object With values

Accessing Values

Values are accessed through keys.

Output:

Setting Keys

Let's add key-value pair to object and then modify it:

Output:

Function

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.

Iterating

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.