JSFiddle - React, Tailwind, and code Playground
JavaScript
function HashArray(){
this.indexKeys = {};
this.storage = [];
}
HashArray.prototype.addUser = function(name, age){
//if length is 10, storage.shift(), and delete
// delete user from indexKeys
if (this.storage.length === 10) {
this.storage.shift();
delete this.indexKeys[name];
}
// add user object {name, age} to storage
// add index of object on storage to indexKeys
// as {name: indexOnStorage}
this.indexKeys[name] = this.storage.length;
this.storage.push({name:name, age:age});
};
HashArray.prototype.getPerson = function(name){
var indexPersonObjLocated = this.indexKeys[name];
return this.storage[indexPersonObjLocated];
};
HashArray.prototype.getStorage = function(){
return this.storage;
};
HashArray.prototype.getKeys = function(){
return this.indexKeys;
};
var coolObj = new HashArray();
coolObj.addUser("White", 24);
coolObj.addUser("Whate", 25);
coolObj.addUser("Plite", 26);