In a dictionary (also called associative array) you can acces objects of an array through a key, which can be a number as well as a string. Thats why you call them key➡value pairs. Dictionaries are used in Python, Java, PHP and many other programming languanges but not in JS! So enjoy this little code snippet.
- use
new dict()
to create a dict object
- use
add(key, value)
to add a key-value-pair (keys have to be unique)
-
use
getByKey(key)
to get a value by its key -
use
length
to get the number of keys (which should also be the number of values) -
use
k(key)
as an alias forgetByKey()
var myDict = new dict();
myDict.add("gitHub", "awesome");
myDict.add("coding", "too");
console.log(myDict.k("coding"));
alert("Dict's length is "+myDict.length)
keep on coding ⌨
\ ゜ o ゜)ノ