-
Notifications
You must be signed in to change notification settings - Fork 0
Home
Akin C edited this page Oct 15, 2017
·
16 revisions
The main chracteristics of dictonary object, it seems, are the key and value property. Even though Javascript doesn`t have a dictonary type, it offers an object type which has the same ability:
var dictonaryObject =
{
anyKeyName: "anyValue", //type "string"
"anotherKey": 42 //type "number" (Key name can be string if wanted)
}
//Getting access to the objects value
dictonaryObject.anyKeyName;
//Another way for a value access
dictonaryObject["anotherKey"];Also the object could contain functions and/or arrays as values. An example could look like as follows:
var dictonaryObject =
{
anyKeyName: function(a)
{
return (a + a);
}
}
//Access
dictonaryObject.anyKeyName(1);//Outputs 2
//Another access
dictonaryObject["anyKeyName"](1); //Outputs 2 Javascripts hasOwnProperty method allows to verify the existence of an objects property as the following example shows:
var dictonaryObject =
{
anyKeyName: function(a)
{
return (a + a);
}
}
//Outputs true
dictonaryObject.hasOwnProperty('anyKeyName');
//Outputs false
dictonaryObject.hasOwnProperty('World');Javascript also allows to overwrite or delete the objects hasOwnProperty method:
STILL IN WORK!
This knowledge was gained:
-
Effective JavaScript "68 Specific Ways to Harness the Power of JavaScript" by David Herman
-
Dictionary Object by Microsoft
-
ASP Dictionary Object by W3Schools
Sources: