It can be done in two ways:
var obj = {
key1: value1,
key2: value2
};
Dot notation:
obj.key3 = "value3";
Square bracket notation:
obj["key3"] = "value3";
When the name of the property is known, the first form is used. We use a second form when the name of the property is dynamically determined.
var getProperty = function (propertyName) {
return obj[propertyName];
};
getProperty("key1");
getProperty("key2");
getProperty("key3");
We can construct a real JavaScript array either by using:
The Array literal notation:
var arr = [];
The Array constructor notation:
var arr = new Array();
If you want to become an expert in web technology, you can check out the latest courses provided by Intellipaat from here.