JSFiddle - React, Tailwind, and code Playground

by JInks Peng

JavaScript

function Dictionary() {
   this.dataStore = new Array();
   this.add = add;
   this.find = find;
   this.remove = remove;
   this.showAll = showAll;
}
function add(key,value) {
   this.dataStore[key] = value;
}
function find(key) {
   return this.dataStore[key];
}
function remove(key) {
   delete this.dataStore[key];
}
function showAll() {
   var keys =  Object.keys(this.dataStore),key;
   for(var i = 0; i < keys.length; ++i) {
      key = keys[i];
      console.log(key + " -> " + this.dataStore[key]);
   }
}
var pbook = new Dictionary();
pbook.add("Mike",123);
pbook.add("David",345);
pbook.add("Cynthia",456);
pbook.showAll();
pbook.remove("David");
pbook.showAll();