Define map function Map () {this.container = {};} Put Key-value into Map Map.prototype.put = function (key, value) {try {if (key! = NULL && Key! = "") this.container[ Key] = value;} catch (e) {return e;}};/ /Remove the corresponding value from the MAP according to key Map.prototype.get = function (key) {try {return this.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.cont Ainer[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;elsereturn false;};/ /Gets the size of Map Map.prototype.size = function () {return this.keyset (). length;} Returns an 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;} 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;} 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.container[keys[i]);} return array;} Returns the and of the value values in the map (valid for the Nunmber type) Map.prototype.sumValues = function () {var values = this.values (); var result = 0;for (var i = 0; i < values.length; i++) {result + = number (Values[i]);} return result;} Calculates the percent value of two integers, function topercent (num, total) {num = parsefloat (num); total = parsefloat (total); if (IsNaN (num) | | IsNaN (Total) {return ' 0 ';} return total <= 0? "0%": (Math.Round (Num/total * 10000)/100.00 + "%"); Return (Math.Round (this * 10000)/100). ToFixed (2) + '% ';}
JavaScript MAP Implementation