Remove duplicate values in the js Array
[Ctrl + A select all Note: If you need to introduce external Js, You need to refresh it to execute]
Method 2
Copy codeThe Code is as follows:
// Deduplication Array
Function unique (data ){
Data = data | [];
Var a = {};
Len = data. length;
For (var I = 0; I <len; I ++ ){
Var v = data [I];
If (typeof (a [v]) = 'undefined '){
A [v] = 1;
}
};
Data. length = 0;
For (var I in ){
Data [data. length] = I;
}
Return data;
}
Method 3
Copy codeThe Code is as follows:
Var arr = ["123", "123", "123", "123", "sfsdf", "123", "345", "123", "123 ", "345", "456", "567", "sdc"];
Var str = [];
For (var I = 0, len = arr. length; I <len; I ++ ){
! RegExp (arr [I], "g"). test (str. join (",") & (str. push (arr [I]);
}
Alert (str );
Method 4
Copy codeThe Code is as follows:
Var pureMulti1 = function (arr ){
Var obj = {};
Var a = [];
For (var I = 0, l = arr. length; iif (! (Arr [I] + "") in obj )){
A. push (arr [I]);
}
Obj [arr [I] = "";
}
Return;
}