The de-weight of an array
The code is as follows:
var arr=[1,1,1,12,2,3,4,4,5];
function Quchong (arrtest) {
var Arrkong=[]; var an empty array that stores the content that is not duplicated
for (Var i=0;i<=arrtest.length;i++) {// Iterate through each element in the array
if (Arrkong.indexof (Arrtest[i]) <0) {//will not duplicate elements, i.e. indexOf The number of <0 is removed
Arrkong.push (Arrtest[i]); Use the push method to place the non-repeating elements into the new array
"
return arrkong;//return value is new array
}
document.write (Quchong (arr)); The result is 1.12,2,3,4,5
II production random verification code
var str1= ' abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz0123456789-_ '; Determine the scope of the Verification code
function Suiji (n) {
var str= '; var an empty string that stores randomly generated characters
for (Var i=0;i<n;i++) { //number of characters required, loop
var Num=math.floor (Math.random () *str1.length); Random string angle Index by random number method
Str+=str1.substring (num,num+1); The resulting string is mapped to the contents of the string and stored in a new string of the previous Var
} return str; Returns a new string
}
Console.log (Suiji (5));
The de-weight of the array, and a random verification code