Array to redo record:
1. IndexOf method, cannot recognize NaN
1 varary = [false,true, Undefined,NULL, NaN, 0, 1, 1, "1", "1", {}, {}, "a", "a", NaN];2 3Array.prototype.uniq =function() {4 var_this = This;5 return_this.filter (function(item, POS) {6 return_this.indexof (item) = =Pos;7 })8}
2, hasOwnProperty, object property detection, Unrecognized 1, ' 1 '
1 varary = [false,true, Undefined,NULL, NaN, 0, 1, 1, "1", "1", {}, {}, "a", "a", NaN];2 3Array.prototype.uniq =function() {4 varMap = {};5 return This. Filter (function(item) {6 returnMap.hasownproperty (item)?false: (Map[item] =true);7 });8}
3. Type of data type, cannot differentiate {}
1 varary = [false,true, Undefined,NULL, NaN, 0, 1, 1, "1", "1", {}, {}, "a", "a", NaN];2 3 4Array.prototype.uniq =function() {5 varPrims = {6 Boolean: {},7 Number : {},8 string: {}9 };Ten varobj = []; One return This. Filter (function(item) { A varType =typeofitem; - if(Typeinchprims) { - returnPrims[type].hasownproperty (item)?false: (Prims[type][item] =true); the}Else { - returnObj.indexof (item)! =-1?false: (Obj.push (item)); - } - }) +}
4, data type + object//effect is good, can accurately distinguish
1 varary = [false,true, Undefined,NULL, NaN, 0, 1, 1, "1", "1", {}, {}, "a", "a", NaN];2 3Array.prototype.uniq =function () {4 varMap = {};5 return This. Filter (function(item) {6 varKey =typeofItem +item;7 Console.log (Key)8 returnMap.hasownproperty (key)?false: (Map[key] =true);9 });Ten};
5, json.stringify//cannot distinguish Nan,null
1 varary = [false,true, Undefined,NULL, NaN, 0, 1, 1, "1", "1", {}, {}, "a", "a", NaN];2 3Array.prototype.uniq =function() {4 varMap = {};5 return This. Filter (function(item) {6 varKey =json.stringify (item);7 returnMap.hasownproperty (key)?false: (Map[key] =true);8 })9}
JavaScript array de-weight (Undefined,null,nan)