SHARE
TWEET

Untitled

a guest Dec 9th, 2018 47 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function Harray(prop, insertMethod){
  2.   this.keyProperty = prop;
  3.   this.h = {};
  4.   this.insertMethod = (insertMethod != null)
  5.                       ? Array.prototype[insertMethod]
  6.                       : Array.prototype.push;
  7. };
  8.  
  9. Harray.prototype = new Array();
  10. Harray.prototype.constructor = Harray;
  11.  
  12. Harray.prototype.add = function(value){
  13.   this.h[value[this.keyProperty]] = value;
  14.   this.insertMethod(value);
  15. };
  16.  
  17. Harray.prototype.remove = function(value){
  18.   delete this.h[value[this.keyProperty]];
  19.   this.splice(this.indexOf(value), 1);
  20. };
  21.  
  22. Harray.prototype.removeKey = function(key){
  23.   this.splice(this.indexOf(this.h[key]), 1);
  24.   delete this.h[key];
  25. };
  26.  
  27. Harray.prototype.removeAt = function(idx){
  28.   delete this.h[this[idx][this.keyProperty]];
  29.   this.splice(idx, 1);
  30. };
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top