Define map function Map () {this.container = {};} Put Key-value into Map Map.prototype.put = function (key, value) {try {if (key! = null) {This.container[key] = value;}} Cat CH (e) {return e;}};/ /Remove the corresponding value from the MAP according to key Map.prototype.get = function (key,deft) {if (!this.containskey (key)) {return deft;} try {return thi S.container[key]; } catch (e) {return e;}};/ /Determine if the MAP contains the specified key Map.prototype.containsKey = function (key) {try {for (var p in This.container) {if (p = = key) return True } return false; } catch (e) {return e;}} Determines whether the Map contains the specified value Map.prototype.containsValue = function (value) {try {for (var p in This.container) {if (This.conta Iner[p] = = = value) return true; } return false; } catch (e) {return e;}};/ /delete the specified key Map.prototype.remove = function (key) {try {delete This.container[key] in Map,} catch (e) {return e;}};/ /empty Map Map.prototype.clear = function () {try {delete this.container; this.container = {};} catch (e) {return e;}};/ /Determine if Map is empty Map.prototype.isEmpty = FunCtion () {if (This.keyset (). Length = = 0) return true; else return false;};/ /Gets the size of Map Map.prototype.size = function () {return this.keyset (). length;} Returns the array of key values in the Map Map.prototype.keySet = function () {var keys = new Array (); for (var p in This.container) {Keys.push (P); } return keys; Traverse MapMap.prototype.each = function (fun) {var keys = This.keyset (), for (var i = 0;i < keys.length;i++) {fun (keys[i],th Is.get (Keys[i])); }}//returns an array of values in Map Map.prototype.values = function () {var valuesarray = new Array (); var keys = This.keyset (); for (Var i = 0; i < keys.length; i++) {Valuesarray.push (this.container[keys[i]);} return valuesarray;} Gets the maximum value of the map, the parameter is the comparison function Map.prototype.max = function (Compare) {var keys = This.keyset (); var maxkey = Keys[0],maxvalue = THIS.G ET (keys[0]); for (var i = 0;i < keys.length;i++) {if (Compare (This.get (keys[i],maxvalue))) {MaxValue = This.get (Keys[i]); Maxkey = key S[i]; }} return [Maxkey,maxvalue];} Returns the EntrySet object in Map Map.prototype.entrySet = function (){var array = new Array (); var keys = This.keyset (); for (var i = 0; i < keys.length; i++) {Array.push (keys[i],this.co Ntainer[keys[i]]); } return array;
JavaScript implements the map structure