This example describes the Map collection tool class for JavaScript implementations. Share to everyone for your reference. as follows:
var Map = function () {//construct Entry entity var Entry = function (key, value) {This.key = key;
This.value = value;
} this.entries = new Array (); Constructs the put method to place a entry This.put = function (key, value) {//array in the array does not put in for (var i = 0; i < this.size (); i++)
{if (This.entries[i].key = = key) {return false;
} this.entries.push (New Entry (key, value));
}; Simulate Get method This.get = function (key) {for (var i = 0; i < this.size (); i++) {if (This.entries[i].key = = Ke
Y) {return this.entries[i].value;
} return null;
};
Lookup Subscript Value This.indexof = function (key) {var index =-1;
for (var i = 0; i < this.size (); i++) {if (This.entries[i].key = = key) {index = i;
Break
} return index;
//Delete an element this.remove = function (key) {var index = this.indexof (key);
if (index!=-1) {This.entries.splice (index, 1); }//Get map length This.siZe = function () {return this.entries.length;
};
Reset key value to This.setvalue = function (key, value) {var index = this.indexof (key);
if (index!=-1) {this.entries[i].value = value;
};
};
is an empty map this.isempty = function () {return this.size () <= 0;
};
Empty map;
This.clear = function () {this.entries = [];
}; Get entry Entity This.getentry = function (index) {if (index >= 0 && Index < this.size ()) {return th
Is.entries[index];
return null;
} this.tostring = function () {var str = ' [';
for (var i = 0; i < this.size (); i++) {str + + this.getentry (i). Key + "=" + this.getentry (i). Value + ",";
}//Remove the Last "," str = str.substring (0, str.length-1);
str = + "]";
return str;
};
}
The
wants this article to help you with your JavaScript programming.