The examples in this article describe the JavaScript analog map output and the method of removing duplicates. Share to everyone for your reference. The specific methods are as follows:
1.Javascriptmap output
function Map () {//private var obj = {};//Empty object container, bearing key value pair//put method this.put = function (key, value) {Obj[key] = VA
Lue//The number of the map container is obtained by binding the key value pair to the Obj object///size Method this.size = function () {var count = 0;
for (var attr in obj) {count++;
return count; The//Get method obtains the value This.get = function (key) {if (Obj[key] | | obj[key] = = 0 | | obj[key] = = False) {return OB
J[key];
else {return null; //remove Delete Method this.remove = function (key) {if (Obj[key] | | obj[key] = = 0 | | obj[key] = false) {Delete Obj[ke
Y];
}///Eachmap Variable map container method This.eachmap = function (fn) {for (var attr in obj) {fn (attr, obj[attr));
The map var m = new map () in simulation Java;
M.put (' The ', ' abc ');
M.put (' A ', false);
M.put (', true ');
M.put (' A ', New Date ());
Alert (M.size ());
Alert (m.get (' 02 '));
M.remove (' 03 ');
Alert (m.get (' 03 '));
M.eachmap (function (key, value) {Alert (key + ":" + value); });
2. Remove duplicates from map
var arr = [2,1,2,10,2,3,5,5,1,10,13];//object
//js object attribute: Key in JS object is never repeated/
*
var obj = new Object ();
Obj.name = ' Z3 ';
Obj.age =;
alert (obj.name);
Obj.name = ' W5 ';
alert (obj.name);
*///
1 The array into a JS object
//2 to the value in the array, into the JS object in the key
//3 to restore the object to the number of groups
///To convert the array to object
function Toobject ( ARR) {
var obj = {};//Private Object
var J;
For (Var i=0, j= arr.length i<j; i++) {
Obj[arr[i]] = true;
}
return obj;
}
Turn this object into a group
function keys (obj) {
var arr = [];//Private object for
(var attr in obj) {
if Obj.hasownproperty (a TTR)) {//yui Underlying code
arr.push (attr);
}
}
return arr;
}
The combined method removes the duplicates in the array
function Uniq (newarr) {return
keys (Toobject (Newarr));
}
Alert (Uniq (arr));
I hope this article will help you with your JavaScript programming.